A Node.js package for handling files and folders in a directory.
Use npm to install the package:
npm install flexfile
Import the package in your Node.js project:
const flexFile = require('flexfile');
Recursively retrieves all files and subfiles in a directory.
fileUtils.getFilesAndSubfiles({
path: '/path/to/directory',
allowedExtensions: ['js', 'txt'], // Optional. Specify the allowed file extensions. Default is ['js'].
avoidFiles: ['example.js'] // Optional. Specify files to avoid. Default is an empty array.
})
.then(files => {
console.log(files);
})
.catch(error => {
console.error(error);
});
Retrieves both files and folders in a directory.
fileUtils.getFilesAndFolders({
path: '/path/to/directory',
allowedExtensions: ['js', 'txt'], // Optional. Specify the allowed file extensions. Default is ['js'].
avoidFiles: ['example.js'], // Optional. Specify files to avoid. Default is an empty array.
})
.then(result => {
console.log('Folders:', result.folders);
console.log('Files:', result.files);
})
.catch(error => {
console.error(error);
});
Retrieves only files in a directory.
fileUtils.getFiles({
path: '/path/to/directory',
allowedExtensions: ['js', 'txt'], // Optional. Specify the allowed file extensions. Default is ['js'].
avoidFiles: ['example.js'], // Optional. Specify files to avoid. Default is an empty array.
})
.then(files => {
console.log(files);
})
.catch(error => {
console.error(error);
});
Retrieves only folders in a directory.
fileUtils.getFolders({
path: '/path/to/directory',
avoidFolder: ['node_modules'] // Optional. Specify folders to avoid. Default is an empty array.
})
.then(folders => {
console.log(folders);
})
.catch(error => {
console.error(error);
});
Recursively retrieves all folders and subfolders in a directory.
fileUtils.getFoldersAndSubfolders({
path: '/path/to/directory',
avoidFolders: ['node_modules'] // Optional. Specify folders to avoid. Default is an empty array.
})
.then(folders => {
console.log(folders);
})
.catch(error => {
console.error(error);
});
This project is licensed under the MIT License.