Skip to main content

Read Directory Node

Read Directory Node Screenshot

Overview

The Read Directory Node reads the contents of a specified directory and outputs an array of filenames. The node can also be configured to read directories recursively, include directories in the output, filter the filenames, return relative paths, and ignore certain files or directories.

If you are using the Rivet SDK, this node requires a native API to be available in the context when the graph is being run. The native API is responsible for providing the functionality to read the contents of a directory.

Inputs

The only inputs for the Read Directory node are toggleable Editor Settings. See that section for possible inputs.

Example 1: Read the contents of a directory

  1. Create a Read Directory Node and set the Path to the directory you want to read.
  2. Run the graph. The Paths output of the Read Directory Node should contain an array of filenames in the specified directory.

Read Directory Node Example 1

Error Handling

The Read Directory Node will error if the native API is not available in the context when the graph is being run. It will also error if the Path input is not provided.

If the directory does not exist or is not accessible, the Paths output will be an array with one element containing the string (no such path).

FAQ

Q: What is a native API?

A: A native API is an object that is responsible for providing native functionality to nodes. It is passed to the context when the graph is being run. The native API must implement the NativeApi interface, which includes methods for reading directories, reading and writing files, and other native operations. See the API Reference for more information.

Q: Can I read directories recursively?

A: Yes, you can set the Recursive input or setting to true to read directories recursively.

Q: What does it mean to include directories in the output?

A: If the Include Directories input or setting is set to true, the Paths output will contain directory names in addition to filenames. For example, if the Path input is set to /Users/username/Documents, the Paths output will contain filenames like file.txt and directory names like subdirectory and subdirectory2.

Q: How to I filter or ignore using globs?

A: Glob patterns are a way to filter filenames using wildcards. For example, to filter out all .txt files, you can do **/*.txt. To filter out all files in a node_modules directory, you can do **/node_modules/**/*.

Q: What does it mean to return relative paths?

A: If the Relative input or setting is set to true, the Paths output will contain relative paths instead of absolute paths. For example, if the Path input is set to /Users/username/Documents, the Paths output will contain filenames like file.txt instead of /Users/username/Documents/file.txt.

See Also