amercier / files-by-directory

NodeJS library to list files by directory, recursively, using asynchronous iteration (for-await-of).
ISC License
2 stars 0 forks source link

showDirectories option #9

Closed amercier closed 5 years ago

amercier commented 5 years ago

options.showDirectories (default: false)

When set to true, includes an entry containing the directory.

# Directory structure:
level1
├── level2
│   ├── file2a
│   └── file2b
├── file1a
└── file1b
for await (const files of filesByDirectory(['level1']/*, { showDirectories: false }*/} )) {
  console.log(files);
}
// [ 'level1/file1a', 'level1/file1b' ]
// [ 'level1/level2/file2a', 'level1/level2/file2b' ]

for await (const files of filesByDirectory(['level1'], { showDirectories: true })) {
  console.log(files);
}
// [ 'level1', 'level1/file1a', 'level1/file1b' ]
// [ 'level1/level2', 'level1/level2/file2a', 'level1/level2/file2b' ]

for await (const [directory, ...files] of filesByDirectory(['level1'], { showDirectories: true })) {
  console.log(directory, files);
}
// level1 [ 'level1/file1a', 'level1/file1b' ]
// level1/level2 [ 'level1/level2/file2a', 'level1/level2/file2b' ]