Node.js module to read the contents of a directory with filters. Provides wrappers to fs.readdir
to return just files or directories.
npm install d-list
- getDirs(path)
- Like
fs.promises.readdir(path)
but only returns directories
- Like
- getDirsSync(path)
- Like
fs.readdirSync(path)
but only returns directories
- Like
- getFiles(path)
- Like
fs.promises.readdir(path)
but only returns directories
- Like
- getFilesSync(path)
- Like
fs.readdirSync(path)
but only returns directories
- Like
example/
├── some_items/
├── another_dir/
├── foo.txt
└── bar.txt
import dl from 'd-list'
const path = 'example'
dl.getDirs(path).then(dirList => {
console.log(dirList)
// ['some_items', 'another_dir']
})
dl.getFiles(path).then(fileList => {
console.log(fileList)
// ['foo.txt', 'bar.txt']
})
example/
├── some_items/
├── another_dir/
├── foo.txt
└── bar.txt
import dl from 'd-list'
const path = 'example'
const dirList = dl.getDirsSync(path)
console.log(dirList)
// ['some_items', 'another_dir']
const fileList = dl.getFilesSync(path)
console.log(fileList)
// ['foo.txt', 'bar.txt']