Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/enumerate-files
List all files in a given directory
https://github.com/shinnn/enumerate-files
asynchronous enumeration filesystem javascript list nodejs promise readdir set
Last synced: 27 days ago
JSON representation
List all files in a given directory
- Host: GitHub
- URL: https://github.com/shinnn/enumerate-files
- Owner: shinnn
- License: isc
- Created: 2017-03-06T10:37:07.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-17T22:28:58.000Z (over 5 years ago)
- Last Synced: 2024-10-15T00:31:37.345Z (about 1 month ago)
- Topics: asynchronous, enumeration, filesystem, javascript, list, nodejs, promise, readdir, set
- Language: JavaScript
- Size: 85 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# enumerate-files
[![npm version](https://img.shields.io/npm/v/enumerate-files.svg)](https://www.npmjs.com/package/enumerate-files)
[![Build Status](https://travis-ci.com/shinnn/enumerate-files.svg?branch=master)](https://travis-ci.com/shinnn/enumerate-files)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/enumerate-files.svg)](https://coveralls.io/github/shinnn/enumerate-files?branch=master)A [Node.js](https://nodejs.org/) module to list all files in a given directory
```javascript
const enumerateFiles = require('enumerate-files');(async () => {
const files = await enumerateFiles('./node_modules/enumerate-files/');
/* Set {
'/Users/example/node_modules/LICENSE',
'/Users/example/node_modules/README.md',
'/Users/example/node_modules/index.js',
'/Users/example/node_modules/package.json'
} */
})();
```## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).
```
npm install enumerate-files
```## API
```javascript
const enumerateFiles = require('enumerate-files');
```### enumerateFiles(*dir* [, *options*])
*dir*: `string` `Buffer` `Uint8Array` `URL` (directory path)
*options*: `Object`
Return: `Promise>`The returned promise is fulfilled with a [`Set`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set) of `string`s or `Buffer`s — absolute paths of all *files* included in a given directory. Symbolic links and directories are excluded.
Every options except for `withFileTypes` are directly passed to the underlying [`readdir-sorted`](https://github.com/shinnn/readdir-sorted#readdirsortedpath--options).
```javascript
(async () => {
const iterator = (await enumerateFiles('/dir')).values();iterator.next().value; //=> '/dir/10.js'
iterator.next().value; //=> '/dir/2a.js'
iterator.next().value; //=> '/dir/2A.js'
})();(async () => {
const iterator = (await enumerateFiles('/dir', {
numeric: true,
caseFirst: 'upper',
encoding: 'buffer'
})).values();iterator.next().value; //=> Buffer.from('/dir/2A.js')
iterator.next().value; //=> Buffer.from('/dir/2a.js')
iterator.next().value; //=> Buffer.from('/dir/10.js')
})();
```## License
[ISC License](./LICENSE) © 2017 - 2018 Shinnosuke Watanabe