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

FilePath

The full file path to extract the directory from.

Type: string

Required: Yes

Example: "C:\Data\Documents\Report.txt"

Output Properties

DirectoryName

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 FilePath is null or empty, DirectoryName will be set to an empty string
  • If the path contains invalid characters (ArgumentException), DirectoryName will contain: "Error: Invalid path - {exception message}"
  • If any other exception occurs, DirectoryName will contain: "Error: {exception message}"
  • The activity does not throw exceptions - errors are indicated in the DirectoryName output

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