Renumbers files to look like this:
01-a-file.html 02-another-file.html 03-...
npm install -g renumber-files
renumber-files [_dir_] [--increment <increment>] [--start <start>] [--dirs]
Will renumber the files in the directory specified, or current directory if not specified.
The delta between each number will be increment, where the default is 1,
and will start at start, where the default is 1. It will exclude
<filename> from the renumbering.
If dirs, then listing will also take into account directories
The package exposes the function
options is an object with the optional fields:
start: from which number to start the numbering. Default 1.
increment: how much to increment each number. Default 1.
separator: what will be the separator between the number and the name. Default '-'.
excludeFiles: an array of filenames to exclude from the renumbering
The renumbering works like this:
- List all files
- For each file, if it is prefixed by digits, grab those digits into a number, and remember. Also remember the number suffix if there are non-digits before separator.
- Sort the files with numbers first. If two files have the same number, use the number suffix. If there is no number suffix, use their names. The numberless files will be last, sorted by name.
- Now remove all numbers from the files with numbers, and renumber according to the sort. Note that files with the same number but a different suffix will still have the same number.
- Renumbering will be
<number><numberSuffix>-<filename>, where number is padded with zeros to make a lexical sort work.