@toolia/process-dir

1.0.2 • Public • Published

process-dir

Quick start

npm i @toolia/process-dir

const processRecursively = require("@toolia/process-dir").default;

processRecursively(inputDirectory, (filename, { level, fullPath, stats}) => /* your code */ )

What is this

This function recursively reads out the paths of files/subdirectories within a given directory.

You are given nested level, fullPath, and fs stats in the callback, for each file/folder found.

Therefore, you could do some processing on recursive files/folders using this tool.

Example

const processRecursively = require("@toolia/process-dir").default;

processRecursively(process.cwd(), (filename, { level, fullPath, stats }) => {
  const isFile = stats.isFile();
  const isJsonFile = isFile && filename.endsWith(".json");
  let msg = "-".repeat(level) + filename;
  console.log(msg);
  //do what you want using fullPath to reference each file / folder.
});

See node.js fs stats

CLI version

You can use this as a command line tool:

npm i @toolia/process-dir -g

process-dir

Specify arguments with --argumentName=argumentValue

For example:

process-dir --directory="some/subdirectory"

You can leave directory empty and it will default to the current working directory of the node script.

List of arguments with defaults:

--help=false
--directory=
--maxLevel=128
--skipDirectories=true
--logJSON=false
--logProcessing=false

Todo:

  • Improve CLI version.

  • Write tests

  • Fix an error "Error: ENOENT: no such file or directory" in rare cases.

Readme

Keywords

Package Sidebar

Install

npm i @toolia/process-dir

Weekly Downloads

6

Version

1.0.2

License

ISC

Unpacked Size

6.29 kB

Total Files

6

Last publish

Collaborators

  • georgecampbell