Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed May 25, 2018
1 parent 06c365b commit 064bcf7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Usage
Usage
$ renamer <options> <files>
-f, --find <string> The find string, or regular expression when --regex is set. If not set, the whole filename will be replaced.
-r, --replace <string> The replace string. With --regex set, --replace can reference parenthesised substrings from --find with $1, $2, $3
-f, --find <string> The find string, or regular expression when --regexp is set. If not set, the whole filename will be replaced.
-r, --replace <string> The replace string. With --regexp set, --replace can reference parenthesised substrings from --find with $1, $2, $3
etc. If omitted, defaults to a blank string. The special token '{{index}}' will insert an incrementing number per
file processed.
-e, --regex When set, --find is interpreted as a regular expression.
-e, --regexp When set, --find is interpreted as a regular expression.
-d, --dry-run Used for test runs. Set this to do everything but rename the file.
-i, --insensitive Enable case-insensitive finds.
-v, --verbose Use to print additional information.
Expand Down Expand Up @@ -134,7 +134,7 @@ $ renamer --find 'Season 1 - ' *
### Simple filename cleanup

```sh
$ renamer --regex --find '.*_(\d+)_.*' --replace 'Video $1.mp4' *
$ renamer --regexp --find '.*_(\d+)_.*' --replace 'Video $1.mp4' *
```

<table>
Expand Down Expand Up @@ -182,7 +182,7 @@ $ renamer --replace 'Image{{index}}.jpg' *
### do something about all those full stops

```sh
$ renamer --regex --find '\.(?!\w+$)' --replace ' ' *
$ renamer --regexp --find '\.(?!\w+$)' --replace ' ' *
```

<table>
Expand All @@ -203,7 +203,7 @@ $ renamer --regex --find '\.(?!\w+$)' --replace ' ' *

### if not already done, add your name to a load of files
```sh
$ renamer --regex --find '(data\d)(\.\w+)' --replace '$1 (checked by Lloyd)$2' *
$ renamer --regexp --find '(data\d)(\.\w+)' --replace '$1 (checked by Lloyd)$2' *
```

<table>
Expand Down Expand Up @@ -257,7 +257,7 @@ $ renamer --find 'pic' --replace 'photo' '**'
### prefix files and folders, recursively

```sh
$ renamer --regex --find '^' --replace 'good-' '**'
$ renamer --regexp --find '^' --replace 'good-' '**'
```

<table>
Expand Down
14 changes: 9 additions & 5 deletions lib/cli-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class CliApp {
const replacer = require('../').replacer
const fileSet = require('file-set')
const fileStats = fileSet(options.files)
/* folders must be renamed last */
const files = fileStats.files.concat(fileStats.dirs)
/* folders must be renamed last, sub-folders must be renamed before folders */
const files = fileStats.files.concat(fileStats.dirs.reverse())
fileStats.notExisting.forEach(function (file) {
this.logReplace(options.verbose, { from: file, error: 'does not exist' })
})
Expand All @@ -43,9 +43,13 @@ class CliApp {
for (const replace of replaces) {
this.logReplace(options.verbose, replace)
}
renamer(replaces).then(() => {
resolve()
})
renamer(replaces)
.then(() => {
resolve()
})
.catch(err => {
this.log(chalk.red(err.stack))
})
}
} else {
this.log(chalk.red('No input files supplied'))
Expand Down
4 changes: 2 additions & 2 deletions lib/cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ exports.optionDefinitions = [
name: 'find',
alias: 'f',
type: String,
description: 'The find string, or regular expression when --regex is set. If not set, the whole filename will be replaced.'
description: 'The find string, or regular expression when --regexp is set. If not set, the whole filename will be replaced.'
},
{
name: 'replace',
alias: 'r',
type: String,
defaultValue: '',
description: "The replace string. With --regex set, --replace can reference parenthesised substrings from --find with $1, $2, $3 etc. If omitted, defaults to a blank string. The special token '\\{\\{index\\}\\}' will insert an incrementing number per file processed."
description: "The replace string. With --regexp set, --replace can reference parenthesised substrings from --find with $1, $2, $3 etc. If omitted, defaults to a blank string. The special token '\\{\\{index\\}\\}' will insert an incrementing number per file processed."
},
{
name: 'regexp',
Expand Down

0 comments on commit 064bcf7

Please sign in to comment.