2.0.1 • Published 4 years ago

cli-foreachfile v2.0.1

Weekly downloads
99
License
MIT
Repository
github
Last release
4 years ago

ForEachFile

Simple CLI utility to recursively execute a command for each matching file.

Examples:

# Visit each .tar file (setting the directory to its location) and untar:
> each '**/*.tar' -- tar xvf %f

# Convert all .jpg images to .png
> each '**/*.jpg' -- convert %b.jpg %b.png

Usage

Usage: each [glob] -- <command>

Options:
  -V, --version            output the version number
  -c, --command <string>   Explicitally specify the command to run
  -d, --dir                Change into each files directory before executing
  -n, --dry-run            Do not run anything, instead show what would be run
                           -implies `-v`
  -g, --glob <expr>        Explicitally specify the glob to use
  -l, --log <expr>         Log text before each execution (default:
                           "${colors.blue('[File]')} %r")
  -p, --parallel <number>  Specify the number of processes to run in parallel
                           (default: 1)
  -v, --verbose            Be verbose
  -h, --help               output usage information

Notes:
  * Command arguments and log output can use ES6 templates or simple percentage prefix characters

Examples:

  # List all basenames from this directory recursively
  each '**/*' -- echo %f

  # Convert all JPG images into PNG
  each '**/*.jpg' -- convert %b.jpg %b.png

Installation

Install globally with NPM:

sudo npm install -g cli-foreachfile

Command expansion

Commands can be written in a variety of ways. Each of the below tokens gets expanded into the value shown.

CategoryTokenExampleDescription
File%bmyfile.fooFile name
"%fmyfile.fooFile name
"{{name}}myfile.fooFile name without extension
"{{base}}myfileFile name
"{{basename}}myfileFile name
"{{relative}}./myfile.foo,File name relative to PWD
"%r./myfile.foo,File name relative to PWD
File Info%efooFile extension
"{{ext}}fooFile extension
Directory%d/foo/bar/baz/myfile.fooRelative dir to pwd
"{{dir}}/foo/bar/bazThe dir portion of the full path
"{{dirname}}/foo/bar/bazThe dir portion of the full path
Full Path%p/foo/bar/baz/myfile.fooFull File path
"{{path}}/foo/bar/baz/myfile.fooFull File path
Utilities{{colors}}Chalk Instance
{{path}}Path NodeJS Core Instance