glob-cmd

0.0.7 • Public • Published

Match files using the patterns the shell uses, like stars and stuff. This is a glob implementation in JavaScript for command line use.

Install globally

If you require() this module, it will return just glob.

npm i glob-cmd -g

Help

A list of all currently possible options.

glob --help
 
  Usage: glob [options]
 
  Options:
 
    -V, --version                output the version number
    -j, --json                   JSON encode matches (default separates by newline)
    -m, --module                 Modulify matches to JS_COMMON module (module.exports)
    -s, --delimiter [separator]  Separate matches by delimiter (default separator is newline)
    -o, --output [filename]      Write to file (write to stdout by default)
    -c, --cwd [directory]        The current working directory in which to search
    -n, --nodir                  Do not match directories, only files (Note: to match only directories, simply put a / at the end of the pattern)
    -h, --help                   output usage information
 

Examples

Simplest

List all .js files in current directory.

Command:

glob *.js

Output:

index.js
utils.js
cli.js
someotherstuff.js

JSON

List mp3 files in current directory and JSON encode matches.

Command:

glob --json *.mp3

Output:

[
   "01. SIR DRUMSALOT.mp3",
   "02. BRAVE.mp3",
   "03. WAKE UP FOOL.mp3",
   "04. THE FEVER IS GROWING.mp3",
   "05. THE LIFE FOR ME.mp3",
   "06. MAKE BELIEVE.mp3",
   "07. FUNNY KIND OF LOVE.mp3",
   "08. WITHOUT YOU.mp3",
   "09. RUNNING.mp3",
   "10. REALITY.mp3",
   "11. IT WILL NOT END.mp3",
   "12. SCREW IT.mp3"
]

Module

List mp3 files in current directory and modulify matches.

Command:

glob --m *.mp3

Output:

module.exports = [
   "01. SIR DRUMSALOT.mp3",
   "02. BRAVE.mp3",
   "03. WAKE UP FOOL.mp3",
   "04. THE FEVER IS GROWING.mp3",
   "05. THE LIFE FOR ME.mp3",
   "06. MAKE BELIEVE.mp3",
   "07. FUNNY KIND OF LOVE.mp3",
   "08. WITHOUT YOU.mp3",
   "09. RUNNING.mp3",
   "10. REALITY.mp3",
   "11. IT WILL NOT END.mp3",
   "12. SCREW IT.mp3"
]

Recursive

List all .js files in all (sub)directories of current directory (c:\codegroundjs).

Command:

glob **/*.js

Outut:

dist/Codeground.js
dist/Codeground.min.js
dist/examples/es5/demo/script.js
dist/examples/es5/script.js
dist/examples/es6/demo/script.js
dist/examples/es6/script.js
dist/examples/fullscreen/demo/script.js
dist/examples/fullscreen/script.js
gulpfile.js
src/Codeground.js
test/test.js

Delimiter (separator)

Use a delimiter to separate matches. In this case, a semi colon.

Command:

glob --delimiter ; *.mp3

Output:

01. SIR DRUMSALOT.mp3;02. BRAVE.mp3;03. WAKE UP FOOL.mp3;04. THE FEVER IS GROWING.mp3;05. THE LIFE FOR ME.mp3;06. MAKE BELIEVE.mp3;07. FUNNY KIND OF LOVE.mp3;08. WITHOUT YOU.mp3;09. RUNNING.mp3;10. REALITY.mp3;11. IT WILL NOT END.mp3;12. SCREW IT.mp3;

Working directory

List all files, directories and subdirectories in node_modules/codegroundjs.

Command:

glob --cwd "e:/npm/node_modules/codegroundjs" **/*

Output:

_config.yml
assets
assets/codeground-rows.png
assets/codeground.png
bower.json
dist
dist/codeground.css
dist/Codeground.js
dist/codeground.min.css
dist/Codeground.min.js
dist/examples
dist/examples/es5
dist/examples/es5/demo
dist/examples/es5/demo/demo.html
dist/examples/es5/demo/script.js
dist/examples/es5/demo/style.css
dist/examples/es5/index.html
dist/examples/es5/script.js
dist/examples/es5/style.css
dist/examples/es6
dist/examples/es6/demo
dist/examples/es6/demo/demo.html
dist/examples/es6/demo/script.js
dist/examples/es6/demo/style.css
dist/examples/es6/index.html
dist/examples/es6/script.js
dist/examples/fullscreen
dist/examples/fullscreen/demo
dist/examples/fullscreen/demo/demo.html
dist/examples/fullscreen/demo/script.js
dist/examples/fullscreen/demo/style.css
dist/examples/fullscreen/index.html
dist/examples/fullscreen/script.js
dist/examples/fullscreen/style.css
gulpfile.js
package.json
README.md
src
src/codeground.css
src/Codeground.js
test
test/test.js

Match only files/directories

Recursively list only files (no directories) in C:\files and write the results as JSON to found.json

Command:

glob --nodir --json --cwd "c:\files" --output found.json **/*

Package Sidebar

Install

npm i glob-cmd

Weekly Downloads

2

Version

0.0.7

License

MIT

Unpacked Size

8.15 kB

Total Files

4

Last publish

Collaborators

  • jochemstoel