GetFileSize Activity
Purpose: This activity gets the size of a file in bytes. It returns both the raw byte count and a human-readable formatted string (e.g., "1.5 MB"). This is useful for checking file sizes before operations, monitoring disk usage, or validating file sizes.
Input Properties
The file path to get the size for. This must be an existing file that is accessible.
Type: string
Required: Yes
Example: "C:\Data\Document.pdf"
Output Properties
File size in bytes.
Type: long
Note: Returns the file size in bytes if successful, or 0 if the file path is empty, if the file does not exist, or if an error occurs.
File size formatted as human-readable string (e.g., '1.5 MB').
Type: string
Note: Returns a formatted string like "1.5 MB" or "500 KB" if successful, "0 bytes" if the file path is empty, "File not found" if the file doesn't exist, or an error message (starting with "Error: ") if an error occurs.
Usage Example
Scenario: Get size of a file Configuration: - FilePath: "C:\Data\Document.pdf" Result: - SizeInBytes: 1572864 - FormattedSize: "1.5 MB" Scenario: Get size of non-existent file Configuration: - FilePath: "C:\Data\NonExistent.txt" Result: - SizeInBytes: 0 - FormattedSize: "File not found"
Error Handling
Important: The activity handles errors gracefully:
- If
FilePathis null or empty,SizeInByteswill be 0 andFormattedSizewill be "0 bytes" - If the file does not exist,
SizeInByteswill be 0 andFormattedSizewill be "File not found" - If access is denied (
UnauthorizedAccessException),SizeInByteswill be 0 andFormattedSizewill contain: "Error: Access denied - {exception message}" - If any other exception occurs,
SizeInByteswill be 0 andFormattedSizewill contain: "Error: {exception message}" - The activity does not throw exceptions - errors are indicated in the outputs
Always check the outputs to verify if the file size was retrieved successfully. Check FormattedSize for error messages.
Important Notes
- The file must exist and be accessible to get its size
- The SizeInBytes output provides the exact byte count for calculations
- The FormattedSize output provides a human-readable format (bytes, KB, MB, GB, TB)
- Formatted sizes are rounded to one decimal place (e.g., "1.5 MB")
- Use this activity before operations that may be affected by file size (e.g., copying large files)
Related Activities
- GetFiles - Get files from a directory
- GetDirectorySize - Get total size of a directory
- GetFileAttributes - Get file attributes