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

FilePath

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"

Attributes

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

Success

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 FilePath is null or empty, Success will be false
  • If the file does not exist, Success will be false
  • If Attributes is null or empty, Success will be false
  • If access is denied (UnauthorizedAccessException), Success will be false
  • If the attributes are invalid (ArgumentException), Success will be false
  • If any other exception occurs, Success will be false
  • The activity does not throw exceptions - errors are indicated by the Success output

Always check the Success output to verify if the attributes were set successfully.

Supported File Attributes

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