Optional
filePath: stringPrivate
_contentProtected
_rootProtected
_getProtected
_getProtected
isChecks if a directory exists. If it doesn't, it creates the directory and any necessary parent directories.
The path of the directory to check or create.
Reads a file line by line and returns an array of strings, where each string is a line from the file.
This method opens a file, reads it line by line, and stores each line as a separate string in an array. It uses an asynchronous iterator to efficiently handle large files without loading the entire content into memory at once.
The path to the file to be scanned.
Searches for files within a specified directory, optionally filtering by file extension.
This method recursively scans a directory and its subdirectories for files. It can filter the results based on a specified file extension or an array of extensions. If no extension is provided, it returns all files. It also has an option to include directories in the results.
The path to the directory to search.
A single file extension or an array of file extensions to filter by. If undefined, no extension filtering is applied.
Optional
showDir: boolean = falseIf true, directories will be included in the results. Defaults to false.
const fileOp = new AioFileOperation();
// Search for all .txt files in the 'mydir' directory
const txtFiles = await fileOp.search('mydir', '.txt');
// Search for all .txt and .md files in the 'mydir' directory
const txtAndMdFiles = await fileOp.search('mydir', ['.txt', '.md']);
// Search for all files and directories in the 'mydir' directory
const allFilesAndDirs = await fileOp.search('mydir', undefined, true);
Extracts the file extension from a given filepath and returns it in lowercase.