'How to copy all files from a directory and all its nested subdirectories in npm?
I want to copy all files (unknown what their names are before hand) in npm, from a structure similar to this:
maindir
-> subdir1
-> subSubdir1
-> filea.js
-> file.js
-> subdir2
-> fileb.js
-> filec.js
I want them to be "flattened" (no subdirectories) in the out directory. And I only want "*.js" files.
I tried (package.json script):
#None of these options works
"copy-files": "copyfiles -f maindir/**/** out"
"copy-files": "copyfiles -f maindir/**/*.js out"
What would the matching expression be?
Solution 1:[1]
You can use ncp module, You can find all of the usage types in given link
Usage is simple: ncp [source] [dest] [--limit=concurrency limit] [--filter=filter] --stopOnErr
Or you can use fs-extra
Solution 2:[2]
This will work to copy files from nested Directories
"copyfiles -u 1 \"./src/**/*.html\" \"dist\""
Solution 3:[3]
I don't believe that NCP is supported anymore and you can do this with copyfiles by doing
copyfiles soruceDir destinationDir
but I would suggest you try the following command line options which will help identify whats going wrong with your copy:
copyfiles -VEau soruceDir/** destinationDir
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | devarakonda |
| Solution 3 | Mr Chow |
