Usage
py-file-attributes dynamically provides the correct handler based on your operating system.
Command Line Interface (CLI)
The package provides a built-in CLI command, file-attributes, which allows you to view or change file attributes directly from the terminal.
View attributes
To see all properties for a specific file, simply pass its path:
Change attributes
You can set or unset supported attributes using boolean flags:
Help Menu
To see which flags are available on your current operating system, use the --help flag. The help menu will display detailed descriptions for each available attribute:
Basic Operations
You can set and get common attributes that are available across all platforms.
from pathlib import Path
from file_attributes import FileAttributes
attrs = FileAttributes(Path("example.txt"))
# Read-only
attrs.set_read_only(True)
print(f"Is read-only: {attrs.read_only}")
# Hidden
attrs.set_hidden(True)
print(f"Is hidden: {attrs.hidden}")
# Check if it's a directory
print(f"Is directory: {attrs.directory}")
Platform-Specific Attributes
Some attributes only make sense on specific operating systems. Be careful when accessing these in cross-platform code, as they will raise an AttributeError if the attribute does not exist on the host OS.
Windows
# Archive
attrs.set_archive(True)
print(attrs.archive)
# Compressed
attrs.set_compressed(True)
print(attrs.compressed)