# @toolia/process-dir

> apply a function to contents of a directory and optional subdirectories

Latest version **1.0.2** (published 2019-12-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install @toolia/process-dir
pnpm add @toolia/process-dir
yarn add @toolia/process-dir
bun add @toolia/process-dir
```

Provides the command `process-dir`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-12-19 |
| First published | 2019-12-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | George Campbell |
| Maintainers | georgecampbell |
| Keywords | command-line, tool |

## Links

- npm: https://www.npmjs.com/package/@toolia/process-dir
- Repository: https://github.com/GCDeveloper/process-dir
- Homepage: https://github.com/GCDeveloper/process-dir#readme
- Issues: https://github.com/GCDeveloper/process-dir/issues
- npm.io page: https://npm.io/package/@toolia/process-dir

## Dependencies (2)

- [esm](https://npm.io/package/esm.md) ^3.2.25
- [@toolia/json-args](https://npm.io/package/@toolia/json-args.md) ^1.1.1

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2019-12-19
- 1.0.0-0 (premajor) — 2019-12-01
- 1.0.1 — 2019-12-02
- 1.0.0 — 2019-12-01

## README

# 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

- Find example in [./example/process-dir.js](./example/process-dir.js)

```
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](https://nodejs.org/api/fs.html#fs_class_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.

---
_Source: https://npm.io/package/@toolia/process-dir · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
