SetFileAttributes Activity
Purpose: This activity sets file attributes (read-only, hidden, etc.) for a file. You can specify one or more attributes as a comma-separated list. This is useful for marking files as read-only, hiding files, or setting other file system properties.
Input Properties
The file path to set attributes for. This must be an existing file that is accessible and writable.
Type: string
Required: Yes
Example: "C:\Data\Document.txt"
File attributes to set. Options: ReadOnly, Hidden, System, Archive, Normal, Temporary, Offline, NotContentIndexed, Encrypted, Compressed, SparseFile, ReparsePoint, Device, NoScrubData, IntegrityStream, NoRecallOnOpen, Pinned, Unpinned, RecallOnOpen, RecallOnDataAccess. Use comma to separate multiple attributes.
Type: string
Required: Yes
Example: "ReadOnly" or "Hidden, Archive" or "ReadOnly, Hidden, System"
Note: Multiple attributes can be specified by separating them with commas. Attribute names are case-insensitive.
Output Properties
True if the file attributes were set successfully, false otherwise.
Type: bool
Note: Returns false if the FilePath is null or empty, if the file does not exist, if Attributes is null or empty, if access is denied, if the attributes are invalid, or if an error occurs.
Usage Example
Scenario: Set file as read-only Configuration: - FilePath: "C:\Data\Document.txt" - Attributes: "ReadOnly" Result: - Success: true Scenario: Set multiple attributes Configuration: - FilePath: "C:\Data\ImportantFile.txt" - Attributes: "ReadOnly, Hidden, Archive" Result: - Success: true
Error Handling
Important: The activity handles errors gracefully:
- If
FilePathis null or empty,Successwill befalse - If the file does not exist,
Successwill befalse - If
Attributesis null or empty,Successwill befalse - If access is denied (
UnauthorizedAccessException),Successwill befalse - If the attributes are invalid (
ArgumentException),Successwill befalse - If any other exception occurs,
Successwill befalse - The activity does not throw exceptions - errors are indicated by the
Successoutput
Always check the Success output to verify if the attributes were set successfully.
Supported File Attributes
ReadOnly- Make file read-onlyHidden- Hide file from normal directory listingsSystem- Mark file as system fileArchive- Mark file for backup or removalNormal- Remove all special attributesTemporary- Mark file as temporaryOffline- Mark file data as not available offlineNotContentIndexed- Prevent file content from being indexedEncrypted- Mark file as encryptedCompressed- Mark file as compressed
Important Notes
- The file must exist and be accessible and writable to set attributes
- Multiple attributes can be specified by separating them with commas (e.g., "ReadOnly, Hidden")
- Attribute names are case-insensitive - "readonly" and "ReadOnly" are equivalent
- Setting attributes replaces existing attributes - use GetFileAttributes first to see current attributes
- Some attributes may require administrator privileges to set
- Use GetFileAttributes to verify attributes after setting them
Related Activities
- GetFileAttributes - Get file attributes
- GetFileSize - Get file size