GetFileName Activity

Purpose: This activity extracts the filename from a full file path. It returns just the filename portion, including the extension, without the directory path. This is useful for getting the name of a file when you only have the full path.

Input Properties

FilePath

The full file path to extract the filename from.

Type: string

Required: Yes

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

Output Properties

FileName

The filename extracted from the path (e.g., 'file.txt' from 'C:\folder\file.txt').

Type: string

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

Usage Example

Scenario: Extract filename from full path

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

Result:
- FileName: "Report.txt"

Scenario: Extract filename from relative path

Configuration:
- FilePath: "Data\Files\Document.pdf"

Result:
- FileName: "Document.pdf"

Error Handling

Important: The activity handles errors gracefully:

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

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

Important Notes

  • This activity does not require the file to exist - it only processes the path string
  • The filename includes the file extension (e.g., "Report.txt")
  • Works with both absolute paths (e.g., "C:\Data\File.txt") and relative paths (e.g., "Data\File.txt")
  • Use GetFileNameWithoutExtension if you need the filename without the extension
  • Use GetExtension if you only need the file extension

Related Activities