The directory path to search, must be a Node path (i.e., similar to POSIX path) or a valid file URL path.
Optional
options: RegExp | LsOptionsAdditional options for reading the directory. Refer to LsOptions documentation for more details.
Optional
type: LsTypesA type to specify the returned file system type to be included.
If not specified or set to 0
, then it will includes all types
(including regular files and directories).
See lsTypes to check all supported types.
A promise that resolves with an array of string representing the
entries result excluding '.'
and '..'
or an empty array ([]
)
if any files and directories does not match with the specified filter options.
Error - If there is an error occurred while reading a directory.
URIError - If the given URL path contains invalid file URL scheme or using unsupported protocols.
// List all installed packages in 'node_modules' directory
ls('node_modules', { exclude: /\.bin/ }, lsTypes.LS_D)
.then((dirs) => console.log(dirs));
// List current directory using an URL object
const { pathToFileURL } = require('node:url');
// ESM: import { pathToFileURL } from 'node:url';
ls(pathToFileURL('.')).then((entries) =>
console.log(entries));
0.1.0
Generated using TypeDoc v0.25.12
Lists files and/or directories in a specified directory path, filtering by a regular expression pattern.
The returned entries are configurable using the additional options, such as listing recursively to subdirectories, and filter specific file and/or directory names using a regular expression.
The additional
options
can be an object or a regex pattern to specify only the match field. If passed as aRegExp
object, the rest options (except thematch
field) for reading the directory will uses default options.If the
options
argument not specified (orundefined
), then it uses the default value:History
1.0.0
As of version 1.0.0, this function now accepts file URL paths. This can be either a string URL path or a
URL
object, and it must follow the'file:'
protocol. AnURIError
will be thrown if the specified file URL path has invalid file URL syntax or is used with unsupported protocols.0.1.0
Added in version 0.1.0.