GetExtension Activity

Purpose: This activity extracts the file extension from a file path. It returns the extension including the leading dot (e.g., ".txt" from "file.txt"). This is useful for determining file types or filtering files by extension.

Input Properties

FilePath

The file path to extract the extension from.

Type: string

Required: Yes

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

Output Properties

Extension

The file extension including the dot (e.g., '.txt' from 'file.txt').

Type: string

Note: Returns the extension with leading dot if successful, an empty string if the file has no extension or if FilePath is null or empty, or an error message (starting with "Error: ") if an error occurs.

Usage Example

Scenario: Extract file extension

Configuration:
- FilePath: "C:\Data\Documents\Report.txt"

Result:
- Extension: ".txt"

Scenario: File with no extension

Configuration:
- FilePath: "C:\Data\File"

Result:
- Extension: "" (empty string)

Error Handling

Important: The activity handles errors gracefully:

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

Note: This activity does not require the file to exist - it only extracts the extension from the path string.

Important Notes

  • This activity does not require the file to exist - it only processes the path string
  • The extension includes the leading dot (e.g., ".txt" not "txt")
  • Only the last extension is returned (e.g., "File.backup.txt" returns ".txt")
  • If the file has no extension, an empty string is returned
  • Works with both absolute paths (e.g., "C:\Data\File.txt") and relative paths (e.g., "Data\File.txt")
  • Use GetFileName to get the full filename, or GetFileNameWithoutExtension to get the filename without extension

Related Activities