GetFileLastWriteTime Activity
Purpose: This activity gets the last write (modification) timestamp of a file. The last write time indicates when the file was last modified or written to. This is useful for tracking file changes, identifying recently modified files, or determining if files need to be processed.
Input Properties
The file path to get the last write time for. This must be an existing file that is accessible.
Type: string
Required: Yes
Example: "C:\Data\Document.txt"
Output Properties
File last write time as DateTime.
Type: DateTime
Note: Returns the last write time if successful, or DateTime.MinValue if the file path is empty, if the file does not exist, or if an error occurs.
File last write time as formatted string.
Type: string
Note: Returns a formatted string like "2024-01-15 14:30:45" if successful, "Invalid path" if FilePath 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 last write time of a file Configuration: - FilePath: "C:\Data\Document.txt" Result: - LastWriteTime: 2024-01-20 10:15:30 (DateTime value) - FormattedLastWriteTime: "2024-01-20 10:15:30" Scenario: Get last write time of non-existent file Configuration: - FilePath: "C:\Data\NonExistent.txt" Result: - LastWriteTime: 0001-01-01 00:00:00 (DateTime.MinValue) - FormattedLastWriteTime: "File not found"
Error Handling
Important: The activity handles errors gracefully:
- If
FilePathis null or empty,LastWriteTimewill beDateTime.MinValueandFormattedLastWriteTimewill be "Invalid path" - If the file does not exist,
LastWriteTimewill beDateTime.MinValueandFormattedLastWriteTimewill be "File not found" - If access is denied (
UnauthorizedAccessException),LastWriteTimewill beDateTime.MinValueandFormattedLastWriteTimewill contain: "Error: Access denied - {exception message}" - If any other exception occurs,
LastWriteTimewill beDateTime.MinValueandFormattedLastWriteTimewill contain: "Error: {exception message}" - The activity does not throw exceptions - errors are indicated in the outputs
Always check the outputs to verify if the last write time was retrieved successfully. Check FormattedLastWriteTime for error messages.
Important Notes
- The file must exist and be accessible to get its last write time
- The LastWriteTime output provides a DateTime value for calculations and comparisons
- The FormattedLastWriteTime output provides a human-readable string in "yyyy-MM-dd HH:mm:ss" format
- Last write time is updated when the file is modified or written to
- This is the most commonly used timestamp for determining if a file has changed
- Use GetFileLastAccessTime to get when the file was last accessed
- Use GetFileCreationTime to get when the file was created
Related Activities
- GetFileLastAccessTime - Get last access time
- GetFileCreationTime - Get creation time
- GetFileSize - Get file size