Rename Multiple Files in a Folder. This can be tweaked several ways
This was inspired by, and is based on a gist by Scriptex, index.js. I have modified it to suit my purpose. I have been downloading books from Zlibrary and the downloaded files have a naming format:
The Key things i want from this file name string are just the file name and authors(s) And i want to rename each file to:
filePattern
to filter for files that need to be renamedauthorPattern
to extract Author name(s), and assign to the variable author
and remove underscoresbookNamePattern
to extract book name and assign to the variable book
and remove underscoresbook
and author
and assign to newName
.book - @author.extension
Files
in the root directory and place the files to be renamed in it.RenameFiles.usePattern(patternClass)
. Then RenameFiles.exec()
RenameFiles.exec({ usePattern: patternClass })
RenameFiles.exec()
returns a Promise: RenameFiles.exec({ usePattern: patternClass }).then( console.log ).catch( console.error );
npm start
, node index
or node .
to run.