Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AfterThreeYears/find-folder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

14 Commits

Repository files navigation

find-folder

Get all files in a directory

🚀 Usage

1. installation

 npm install --save find-folder

2. Usage:

If you have the following folders

➜ root pwd
/tmp/root
➜ root tree
.
├── a
│  └── index.js
└── b
 └── index.js
const find = require('find-folder');
(async () => {
 const data = await find('/tmp/root');
 console.log(data);
})();
// Return the following contents
// [ { path: '/tmp/root', type: 'dir' },
// { path: '/tmp/root/a', type: 'dir' },
// { path: '/tmp/root/b', type: 'dir' },
// { path: '/tmp/root/a/index.js', type: 'file' },
// { path: '/tmp/root/b/index.js', type: 'file' } ]

3. option:

path: Initialization path, example

const find = require('find-folder');
(async () => {
 const data = await find({ path: '/tmp/root' });
 console.log(data);
})();
// Return the following contents
// [ { path: '/tmp/root', type: 'dir' },
// { path: '/tmp/root/a', type: 'dir' },
// { path: '/tmp/root/b', type: 'dir' },
// { path: '/tmp/root/a/index.js', type: 'file' },
// { path: '/tmp/root/b/index.js', type: 'file' } ]

type: There are two ways to search: DFS depth first and BFS breadth first, default breadth first.

const find = require('find-folder');
(async () => {
 const data = await find({ path: '/tmp/root', type: 'DFS' });
 console.log(data);
})();
// Return the following contents
// [ { path: '/tmp/root', type: 'dir' },
// { path: '/tmp/root/a', type: 'dir' },
// { path: '/tmp/root/a/index.js', type: 'file' },
// { path: '/tmp/root/b', type: 'dir' },
// { path: '/tmp/root/b/index.js', type: 'file' } ]

ignore: Ignored folder

const find = require('find-folder');
(async () => {
 const data = await find({ path: '/tmp/root', ignore: ['/tmp/root/b'] });
 console.log(data);
})();
// Return the following contents
//[ { path: '/tmp/root', type: 'dir' },
// { path: '/tmp/root/a', type: 'dir' },
// { path: '/tmp/root/a/index.js', type: 'file' },

depth: Depth of search

const find = require('find-folder');
(async () => {
 const data = await find({ path: '/tmp/root', ignore: ['/tmp/root/b'] });
 console.log(data);
})();
// Return the following contents
// [ { path: '/tmp/root', type: 'dir' },
// { path: '/tmp/root/a', type: 'dir' },
// { path: '/tmp/root/b', type: 'dir' } ]

file type:

{
 FILE: 'FILE',
 DIRECTORY: 'DIRECTORY',
 SYMBOLICLINK: 'SYMBOLICLINK',
 FIFO: 'FIFO',
 SOCKET: 'SOCKET',
 BLOCKDEVICE: 'BLOCKDEVICE',
 CHARACTERDEVICE: 'CHARACTERDEVICE',
 UNKNOWN: 'UNKNOWN',
}

4. unit testing:

 npm run test
> find-folder@0.0.2 test find-folder
> sh ./test/dir.sh && jest
 PASS test/index.test.js
 ✓ defualt (36ms)
 ✓ BFS (17ms)
 ✓ DFS (3ms)
 ✓ ignore (4ms)
 ✓ deep (2ms)
 ✓ test type (1ms)
Test Suites: 1 passed, 1 total
Tests: 6 passed, 6 total
Snapshots: 0 total
Time: 1.204s
Ran all test suites.

About

find-folder Get all files in a directory

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /