node.js - NodeJS - Copy and Rename all contents in existing directory recursively -


I have a directory within folders and files. I want to copy the whole directory with a whole directory to a different location, while wanting to rename all the files to make it more meaningful. I want to use nodes to complete this series of operations. What is an easy way to do this, besides moving it one by one and changing it one by one?

Thank you.

- Thanks for the comment! So here's an example directory that I have to keep in mind:

  -Mfridge - MyFood TTT - MyPell Txt - MyOrange.txt - ... - Myrrink - MySoda - MyDiThAKAK. .txt - ... - MyDesserts - MyIce ...  

For example, I want to replace "My" with "Tom", and I also get the name of "My" I would like to replace Tom in all the text files using a node-fs-extract, I am able to copy the directory to a different location, but I have a hard time with the change of name of the file names.

Set up your device

 Requires  const fs = ('FS'); Const Path = Requirement ('Path'); Rename FunctionReserveScreens (from DIR, from) {fs.readdirSync (DIR) .for unit (this => {itsPath = path.resolve (dir, it); const itsStat = fs.statSync (itsPath); if (Its position isDirectory ()) {renameFilesRecursive (itsPath, from, to)} else {if (itsPath.search (from)! = -1) {fs.renameSync (itsPath, itsPath.replace (from, to))}} })}}  

Usage

  const dir = path.resolve (__Dirname, 'src / app '); RenameFilesRecursive (DIR, / ^ My /, 'Tom'); RenameFilesRecursive (dir, /\.txt$/, '.class');  

Comments