Efficiently scans a folder to extract filenames, extensions, and full directory paths, supporting recursive traversal.
npm install scan-the-folder
A Node.js utility to recursively maps all files in a folder, extracting each file's name, extension, full directory path, and providing file handles for convenient file access.
Using npm (for import or CLI):
npm install -g scan-the-folder # global install for CLI usage
or
npm install scan-the-folderlder # local install to use as a module
After global installation, run the following command in your terminal:
scan-the-folderlder -f <directory>Example:
scan-the-folderlder -f ./my-folderThis will output a list of files scanned in the given directory (implement your CLI output as desired).
CLI Options
Specifies the folder to scan. Only one folder can be provided.
One or more directory names to ignore during the scan. Use this to exclude folders like node_modules or .git.
One or more file names or extensions to include exclusively. If specified, only these files will be processed.
One or more file names to ignore during the scan.
You can also import and use scan-the-folder in your Node.js or TypeScript projects:
import { getFilesWithHandlesRecursively } from 'scan-the-folder';const files = getFilesWithHandlesRecursively('./my-folder', {
ignoreDirs: ['node_modules', '.git'],
ignoreFiles: ['README.md'],
whitelistFiles: ['index.ts', 'index.js'] // Only include these extensions
});
files.forEach(file => {
console.log(Found file: ${file.fullPath} (${file.extension}));
// Access the file content using file.handle (fs.ReadStream)
});
ignoreDirs: string[] — Folder names to ignoreignoreFiles: string[] — File names to ignorewhitelistFiles: string[] — File names to include (if set, only these are included)
Returns an array of FileInfo objects:
interface FileInfo {
name: string; // File name without extension
extension: string; // File extension (e.g., '.js')
directory: string; // Absolute directory path of the file
fullPath: string; // Relative file path from the input directory
}
MIT License © pSkywalker
Contributions, issues, and feature requests are welcome!
Created by pSkywalker. Feel free to open an issue or submit a pull request.