cpy-cli is a command-line interface for copying files and directories with advanced features including glob pattern support, stream-based processing for performance, graceful filesystem handling, and flexible options for controlling copy behavior.
npm install --global cpy-clicpy <source ...> <destination># Copy a single file
cpy source.txt dest/
# Copy files with glob patterns
cpy 'src/*.png' dist/
# Copy with exclusion patterns
cpy 'src/*.png' '!src/goat.png' dist/
# Copy all files preserving directory structure
cpy . '../dist/' --cwd=src
# Copy with file renaming using templates
cpy 'src/*.png' dist --rename=hi-{{basename}}cpy-cli is built as a command-line wrapper around the programmatic cpy library. Key architectural components:
meow library for argument parsing and help text generationcpy library (v12.0.0+)cpy librarycpy dependency{{basename}} placeholder in rename operationsThe CLI acts as a thin interface layer, providing user-friendly options that map directly to cpy library parameters.
Primary command for copying files and directories with advanced pattern matching and processing options.
cpy <source ...> <destination> [options]Parameters:
<source ...> - One or more source file paths or glob patterns. Supports negation patterns with ! prefix<destination> - Target directory path where files will be copiedControl whether existing files at the destination should be overwritten.
--no-overwriteBy default, cpy-cli will overwrite existing files. Use --no-overwrite to prevent overwriting and throw an error when a destination file already exists.
Usage Example:
# Prevent overwriting existing files
cpy source.txt dest --no-overwriteSpecify the working directory for source file operations.
--cwd=<directory>Parameters:
<directory> - Path to the working directory (defaults to current working directory)Usage Example:
# Copy files relative to a specific directory
cpy '*.js' ../output --cwd=srcRename all source files using a template pattern with placeholder substitution.
--rename=<filename>Parameters:
<filename> - Target filename pattern supporting {{basename}} template placeholderThe {{basename}} placeholder gets replaced with the original filename without extension. The original file extension is preserved automatically.
Usage Examples:
# Rename all files to a fixed name
cpy 'src/*.png' dist --rename=logo.png
# Add prefix using basename template
cpy 'src/*.png' dist --rename=hi-{{basename}}
# Multiple placeholders supported
cpy 'src/*.png' dist --rename={{basename}}-copy-{{basename}}Control whether patterns match files that begin with a period (hidden files).
--dotBy default, glob patterns do not match dotfiles. Use --dot to include hidden files in pattern matching.
Usage Example:
# Include hidden files in copy operation
cpy '**/*' dest --dotFlatten the directory structure, placing all copied files in the same destination directory.
--flatUsage Example:
# Copy all .js files to dest/ without preserving directory structure
cpy '**/*.js' dest --flatControl the number of files being copied concurrently for performance optimization.
--concurrency=<number>Parameters:
<number> - Number of concurrent file operations (defaults to CPU cores × 2)Usage Example:
# Limit concurrent operations
cpy 'src/**/*' dest --concurrency=4Source arguments support glob patterns for flexible file selection:
* - Match any filename** - Match any directory path recursively? - Match any single character[abc] - Match any character in brackets{foo,bar} - Match any string in bracesExamples:
# All PNG files in src directory
cpy 'src/*.png' dist
# All files recursively
cpy 'src/**/*' dist
# Specific file extensions
cpy 'src/**/*.{js,ts}' distUse ! prefix to exclude files from selection:
# Copy all PNG files except goat.png
cpy 'src/*.png' '!src/goat.png' dist
# Copy all JS files except test files
cpy 'src/**/*.js' '!src/**/*.test.js' distThe command handles errors gracefully and provides clear error messages:
--no-overwrite is used and destination file existsExit codes:
0 - Success1 - Error occurred# Copy specific file types from multiple directories
cpy 'src/**/*.{png,jpg,gif}' 'assets/**/*.svg' dist/images
# Copy with multiple exclusions
cpy 'src/**/*' '!src/node_modules/**' '!src/.git/**' '!src/**/*.test.*' backup/# Preserve structure with specific working directory
cpy '**/*.md' ../docs --cwd=src
# Flatten deeply nested files
cpy 'src/**/*.config.{js,json}' config/ --flat
# Copy entire directory structure
cpy 'src/**/*' dist --cwd=src# Add timestamp prefix (using basename)
cpy '*.log' archive/ --rename=2024-01-01-{{basename}}
# Convert to different naming convention
cpy 'src/*.component.ts' dist/ --rename={{basename}}.comp# High concurrency for many small files
cpy 'assets/**/*.png' dist/ --concurrency=16
# Lower concurrency for large files
cpy '*.iso' backup/ --concurrency=2