list-directories
v1.1.0
Published
List all directories in a given directory
Downloads
2,082
Maintainers
Readme
list-directories
List all directories in a given directory
const listDirectories = require('list-directories');
/*
./my-dir/a: file
./my-dir/b: directory
./my-dir/c: symlink to a directory
./my-dir/d: directory
*/
(async () => {
await listDirectories('my-dir');
/* => Set {
'/Users/example/my-dir/b',
'/Users/example/my-dir/d'
} */
})();
Installation
npm install list-directories
API
const listDirectories = require('list-directories');
listDirectories(dir)
dir: string
Buffer
URL
(directory path)
options: Object
(readdir-sorted
options)
Return: Promise<Set<string>>
The promise will be fulfilled with a Set
of strings — absolute paths of all directories included in the given directory.
Options are directly passed to the underlying readdir-sorted
to control the order of results.
listDirectories('/dirs').then(files => {
const iterator = files[Symbol.iterator];
iterator.next().value; //=> '/dirs/10'
iterator.next().value; //=> '/dirs/2a'
iterator.next().value; //=> '/dirs/2A'
});
listDirectories('/dirs', {
numeric: true,
caseFirst: 'upper'
}).then(files => {
const iterator = files[Symbol.iterator];
iterator.next().value; //=> '/dirs/2A'
iterator.next().value; //=> '/dirs/2a'
iterator.next().value; //=> '/dirs/10'
});
License
ISC License © 2018 Shinnosuke Watanabe