Install copyfiles via npm
masterInstall the copyfiles CLI globally using npm to make the copyfiles and copyup commands available in your terminal.
npm install copyfiles -grepository·master·Indexed 19 days ago
https://github.com/calvinmetcalf/copyfilesA utility for copying files and directories supporting globs and directory structure manipulation. Available as a CLI tool with commands like `copyfiles` and `copyup`, or as a programmatic Node.js API. Features include flattening output, slicing paths off the bottom, excluding specific patterns, and following symbolic links.
Install the copyfiles CLI globally using npm to make the copyfiles and copyup commands available in your terminal.
npm install copyfiles -gThe copyup command is a specialized version of copyfiles used to slice a specific number of path segments off the bottom of the source paths. When using copyup, the -u (or --up) flag defaults to 1 if not otherwise specified.
Example:
If you want to slice 1 level off the path, you can simply use copyup or copyfiles -u 1.
# Using the specialized command (defaults to -u 1)
copyup inFile outDirectory
# Using the standard command with explicit slice
copyfiles -u 1 inFile outDirectoryThe up option determines how the directory structure of the source files is mapped to the destination directory.
up: 0 (Default): The full path from the source is recreated inside the destination directory.up: true: Only the basename (the filename itself) is used. All files are flattened into the destination directory.up: n (where n is a positive integer): The first n segments of the path are stripped. For example, if up: 1 and the file is a/b/c.txt, the destination will contain b/c.txt relative to the output directory.Note: If you attempt to set up to a value greater than the actual depth of the path, the function will throw an error: 'cant go up that far'.
copyFiles will overwrite files if they already exist in the destination. To prevent this, set the soft option to true in your configuration object. When soft is enabled, the function checks for the existence of the destination file using fs.stat and skips the copy operation if the file is already present.~) to represent the home directory in source or destination paths on Windows, you must include either the -u (up) or -f (flat) option, or use the copyup command. Failure to do so will result in an Error: Illegal characters in path.Use the -e or --exclude option to provide a pattern or glob that should be ignored during the copy process. This option can be used multiple times.
copyfiles -e "**/*.test.js" -f ./foo/**/*.js outUse the -f or --flat option to prevent the creation of subdirectories in the destination. Instead, all files from the source patterns will be placed directly into the output directory.
Example: If you have ./foo/a.txt and ./foo/bar/b.txt, using -f will put both a.txt and b.txt directly into the out folder.
copyfiles -f ./foo/*.txt ./foo/bar/*.txt outIf your source files are inside a directory structure that you do not want replicated in the destination, use the -u or --up option followed by a number. This number represents how many levels of the path to strip from the bottom.
Example: copyfiles -u 1 something/*.js out will take files from something/ and place them directly in out/ instead of out/something/.
copyfiles -u 1 something/*.js outYou can use copyfiles as a Node.js module. The function takes an array of paths, an optional configuration argument, and a callback function.
Arguments:
[paths]: An array of strings. The last element in the array is the destination path.opt: An optional argument which can be:number: Sets the --up option.true: Sets the --flat option.object: A hash of the various options (using the long names: up, all, flat, exclude, error, verbose, follow, and soft).callback: A function called when the operation is complete.var copyfiles = require('copyfiles');
copyfiles([paths], opt, callback);The following options are available for the copyfiles command:
| Flag | Long Flag | Description |
|---|---|---|
-u, --up | up | Slice a path off the bottom of the paths (takes a [number]) |
-a, --all | all | Include files & directories beginning with a dot (.) [boolean] |
-f, --flat | flat | Flatten the output into a single directory [boolean] |
-e, --exclude | exclude | Pattern or glob to exclude (can be passed multiple times) |
-E, --error | error | Throw error if nothing is copied [boolean] |
-V, --verbose | verbose | Print more information to console [boolean] |
-s, --soft | soft | Do not overwrite destination files if they exist [boolean] |
-F, --follow | follow | Follow symbolic links [boolean] |
-v, --version | version | Show version number [boolean] |
-h, --help | help | Show help [boolean] |
Options:
-u, --up slice a path off the bottom of the paths [number]
-a, --all include files & directories begining with a dot (.) [boolean]
-f, --flat flatten the output [boolean]
-e, --exclude pattern or glob to exclude (may be passed multiple times)
-E, --error throw error if nothing is copied [boolean]
-V, --verbose print more information to console [boolean]
-s, --soft do not overwrite destination files if they exist [boolean]
-F, --follow follow symbolink links [boolean]
-v, --version Show version number [boolean]
-h, --help Show help [boolean]copyup command is identical to copyfiles, but it sets the --up (or -u) option to 1 by default.The copyfiles command copies files and directories to a destination directory. The last argument provided is always treated as the output directory, which will be created if it does not exist. You can provide multiple input files or globs.
Note for Windows users: Globs must be double quoted (e.g., "*.js"). On other platforms, quoting is optional but recommended for globstars.
Basic Usage:
copyfiles [options] inFile [more files ...] outDirectorycopyfiles foo foobar foo/bar/*.js out