GetDirectoryName Activity
Purpose: This activity extracts the directory path from a full file path. It returns the directory portion without the filename. This is useful for getting the folder location of a file or for navigating to the parent directory.
Input Properties
The full file path to extract the directory from.
Type: string
Required: Yes
Example: "C:\Data\Documents\Report.txt"
Output Properties
The directory path (e.g., 'C:\folder' from 'C:\folder\file.txt').
Type: string
Note: Returns the directory path if successful, an empty string if FilePath is null or empty or if there is no directory portion, or an error message (starting with "Error: ") if an error occurs.
Usage Example
Scenario: Extract directory from full path Configuration: - FilePath: "C:\Data\Documents\Report.txt" Result: - DirectoryName: "C:\Data\Documents" Scenario: Extract from root file Configuration: - FilePath: "C:\File.txt" Result: - DirectoryName: "C:\"
Error Handling
Important: The activity handles errors gracefully:
- If
FilePathis null or empty,DirectoryNamewill be set to an empty string - If the path contains invalid characters (
ArgumentException),DirectoryNamewill contain: "Error: Invalid path - {exception message}" - If any other exception occurs,
DirectoryNamewill contain: "Error: {exception message}" - The activity does not throw exceptions - errors are indicated in the
DirectoryNameoutput
Note: This activity does not require the file or directory to exist - it only extracts the directory path from the path string.
Important Notes
- This activity does not require the file or directory to exist - it only processes the path string
- The directory path does not include a trailing backslash (except for root paths like "C:\")
- Works with both absolute paths (e.g., "C:\Data\File.txt") and relative paths (e.g., "Data\File.txt")
- For root-level files (e.g., "C:\File.txt"), returns the root directory (e.g., "C:\")
- Use GetFileName to get the filename portion of the path
- Use CombinePath to combine directory and filename paths
Related Activities
- GetFileName - Get filename from file path
- CombinePath - Combine directory and filename paths
- GetDirectories - Get subdirectories in a directory