75lb / renamer

Rename files in bulk.
MIT License
529 stars 30 forks source link

Folder index replace in reverse order #32

Closed ebastidas closed 6 years ago

ebastidas commented 6 years ago

This issue might be an extension of #31 or a bug of the current code.

I needed to rename folders using {{index}}, and I don't know if the current code has a bug because it incorrectly sorts the folders in descending order instead of ascending order (which is the correct order). This only happens in renaming folders, but it works fine when renaming files.

I'm using this command:

renamer --replace '{{index}}' *

When renaming (text) files, it correctly produce:

IMG_5776.txt -> 1 IMG_5777.txt -> 2 IMG_5778.txt -> 3

But with folders it happens the following:

IMG_5778 -> 1 IMG_5777 -> 2 IMG_5776 -> 3

To fix temporarily my issue to rename folders correctly I changed this line (https://github.com/75lb/renamer/blob/master/lib/renamer.js#L59):

results.list = options.files.map(replaceSingle.bind(null, findRegex, options.replace))

to

results.list = options.files.reverse().map(replaceSingle.bind(null, findRegex, options.replace))

But this would obviously brake the functionality of files renaming using index. @75lb Would be nice is this issue would be address. Thanks

75lb commented 6 years ago

Reproduced, looking into this.

75lb commented 6 years ago

Is this still an issue in renamer v1?

75lb commented 6 years ago

fixed and released in renamer v1.0.0.