List Directory
AI-generatedOverview
The node performs a 'List Directory' operation to list files and folders within a specified directory path. It supports filtering by files, directories, or both, and allows customization of traversal depth, sorting criteria, and sorting direction. Users can apply regular expression filters to include or exclude specific files or directories, limit the number of returned records, and choose to return either a single object or an array of results. This node is useful for scenarios where users need to explore directory contents programmatically, such as automating file management, auditing directory structures, or preparing file lists for further processing.
Use Case Examples
- Listing all files and directories in a given folder up to a depth of 3, sorted by modification time in descending order.
- Filtering to list only directories that have no subdirectories (leaf folders) within a specified path.
- Limiting the output to the first 50 files matching a specific pattern, excluding certain file types using regex.
Properties
| Name | Meaning |
|---|---|
| Directory Path | The path of the directory to list contents from. Required for the operation. |
| Show | Determines whether to list files only, directories only, or both files and directories. |
| Only Leaf Folders | If selected, only directories without subdirectories (leaf folders) are returned. Applicable when showing directories or both. |
| Max Depth | Maximum directory depth to traverse, ranging from 1 to 9. |
| Sort By | Criteria to sort the results by, such as name, modified time, type, size, depth, full path, or parent directory. |
| Sort Direction | Direction to sort the results, either ascending or descending. |
| Filter Pattern | Regular expression pattern to include files or directories matching the pattern. |
| Exclude Pattern | Regular expression pattern to exclude files or directories matching the pattern. |
| Maximum Records | Limits the maximum number of records returned to avoid memory issues, ranging from 1 to 5000. |
| Return Single Object | If true, returns a single object instead of an array. If multiple results are found, only the first is returned; if none, returns an empty object. |
Output
JSON
datas- An array of objects representing the files and directories found, or a single object if 'Return Single Object' is true.
Troubleshooting
- Ensure the 'Directory Path' parameter is provided and points to a valid directory; otherwise, the node will throw an error.
- Regular expression patterns for 'Filter Pattern' and 'Exclude Pattern' must be valid; invalid regex can cause errors or unexpected filtering results.
- If 'Return Single Object' is enabled but no results are found, the node returns an empty object, which might require handling downstream.