@zebrajaeger/filewalker
v2.0.2
Published
Walk through filesystem
Downloads
1
Readme
Filewalker
Simple synchron filewalker for node and local filesystem.
Install
npm install --save @zebrajaeger/filewalker
yarn add @zebrajaeger/filewalker
Examples
Basic
const {FileWalker} = require('@zebrajaeger/filewalker');
// create instance
const fileWalker = new FileWalker('/media/l/Seagate');
// start (returns Promise so we call '.then()')
fileWalker.walk((f) => console.log('File', f), (d)=> console.log('Directory', d)).then();
returns i.E.
[...]
Directory { abs: '/media/l/Seagate/Seagate', rel: 'Seagate' }
Directory {
abs: '/media/l/Seagate/Seagate/Registration',
rel: 'Seagate/Registration'
}
File {
abs: '/media/l/Seagate/Seagate/Registration/SerialNumber.xml',
rel: 'Seagate/Registration/SerialNumber.xml'
}
[...]
Start deeper but get the relative path to root directory.
const {FileWalker} = require('@zebrajaeger/filewalker');
const fileWalker = new FileWalker('/media/l/Seagate');
fileWalker.walk(
(f) => console.log('File', f),
(d)=> console.log('Directory', d),
{relStart: 'Seagate'}).then();
returns i.E.
Example with files and directories
const {FileWalker} = require('@zebrajaeger/filewalker');
walkSync(
'.',
(file) => console.log('File:', file),
(dir) => console.log('Directory:', dir)
).then();
Example files only
const {FileWalker} = require('@zebrajaeger/filewalker');
walkSync(
'.',
(file) => console.log('File:', file)
).then();
Example directories only
const {FileWalker} = require('@zebrajaeger/filewalker');
walkSync(
'.',
null,
(dir) => console.log('Directory:', dir)
).then();