GetFiles Activity

Purpose: This activity gets all files in a specified directory. You can optionally filter files by a search pattern and choose to search only the top directory or all subdirectories. The results are returned as a JSON array of file paths, making it easy to process multiple files in workflows.

Input Properties

DirectoryPath

The directory path to search in. This must be an existing directory that is accessible.

Type: string

Required: Yes

Example: "C:\Data\Documents"

SearchPattern

Search pattern for file names (e.g., '*', '*.txt', 'temp*').

Type: string

Default: "*"

Example: "*.txt" for text files, "*.xlsx" for Excel files, "temp*" for files starting with "temp"

Note: Use "*" to get all files, or specify a pattern like "*.txt" to filter by extension.

SearchOption

Search option: 'TopDirectoryOnly' or 'AllDirectories'.

Type: string

Default: "TopDirectoryOnly"

The valid values are:

  • TopDirectoryOnly - Search only in the specified directory (default)
  • AllDirectories - Search in the specified directory and all subdirectories

Output Properties

Files

Array of file paths as JSON string.

Type: string

Note: Returns a JSON array string like ["C:\\Data\\File1.txt", "C:\\Data\\File2.txt"] if successful, an empty JSON array "[]" if no files are found or if the directory path is empty, or an error message (starting with "Error: ") if an error occurs.

Count

Number of files found.

Type: int

Note: Returns the count of files found if successful, or 0 if no files are found, if the directory path is empty, or if an error occurs.

Usage Example

Scenario: Get all files in a directory

Configuration:
- DirectoryPath: "C:\Data\Documents"
- SearchPattern: "*"
- SearchOption: "TopDirectoryOnly"

Result:
- Files: "[\"C:\\\\Data\\\\Documents\\\\File1.txt\", \"C:\\\\Data\\\\Documents\\\\File2.pdf\"]"
- Count: 2

Scenario: Get only text files recursively

Configuration:
- DirectoryPath: "C:\Data"
- SearchPattern: "*.txt"
- SearchOption: "AllDirectories"

Result:
- Files: "[\"C:\\\\Data\\\\File1.txt\", \"C:\\\\Data\\\\SubFolder\\\\File2.txt\"]"
- Count: 2

Error Handling

Important: The activity handles errors gracefully:

  • If DirectoryPath is null or empty, Files will be set to "[]" and Count will be 0
  • If the directory does not exist (DirectoryNotFoundException), Files will be set to "[]" and Count will be 0
  • If access is denied (UnauthorizedAccessException), Files will contain: "Error: Access denied - {exception message}" and Count will be 0
  • If any other exception occurs, Files will contain: "Error: {exception message}" and Count will be 0
  • The activity does not throw exceptions - errors are indicated in the Files output

Always check the Files output to verify if the operation succeeded. If the string starts with "Error: ", the operation failed. Otherwise, it contains a valid JSON array.

Important Notes

  • The DirectoryPath must point to an existing directory that is accessible
  • The SearchPattern supports wildcards: "*" matches any characters, "?" matches a single character
  • Use SearchOption "AllDirectories" to search recursively through subdirectories
  • The Files output is a JSON array string that can be parsed to get individual file paths
  • Use the Count output to quickly determine how many files were found
  • Searching with "AllDirectories" may take longer for directories with many subdirectories

Related Activities