Module sysbot.modules.windows.file

Windows File System Module

This module provides comprehensive file system operations for Windows systems, including file type checking, attribute retrieval, content operations, and ACL (Access Control List) management using PowerShell.

Classes

class File

Windows file system operations class using PowerShell.

Ancestors

Methods

def attributes(self, alias: str, path: str, **kwargs) ‑> dict

Get file or directory attributes.

Args

alias
Session alias for the connection.
path
Path to query.
**kwargs
Additional command execution options.

Returns

Dictionary containing file/directory attributes including Name, FullName, Length, CreationTime, LastWriteTime, LastAccessTime, Attributes, and Extension.

def contains(self, alias: str, path: str, pattern: str, **kwargs) ‑> bool

Check if file contains a pattern.

Args

alias
Session alias for the connection.
path
Path to the file.
pattern
Pattern to search for.
**kwargs
Additional command execution options.

Returns

True if pattern is found in the file, False otherwise.

def content(self, alias: str, path: str, **kwargs) ‑> str

Get file content.

Args

alias
Session alias for the connection.
path
Path to the file.
**kwargs
Additional command execution options.

Returns

File content as a string.

def is_directory(self, alias: str, path: str, **kwargs) ‑> bool

Check if path is a directory.

Args

alias
Session alias for the connection.
path
Path to check.
**kwargs
Additional command execution options.

Returns

True if path is a directory, False otherwise.

def is_file(self, alias: str, path: str, **kwargs) ‑> bool

Check if path is a file.

Args

alias
Session alias for the connection.
path
Path to check.
**kwargs
Additional command execution options.

Returns

True if path is a file, False otherwise.

def is_present(self, alias: str, path: str, **kwargs) ‑> bool

Check if a file or directory exists.

Args

alias
Session alias for the connection.
path
Path to check.
**kwargs
Additional command execution options.

Returns

True if path exists, False otherwise.

def list_directory(self, alias: str, path: str, **kwargs) ‑> list

List contents of a directory.

Args

alias
Session alias for the connection.
path
Path to the directory.
**kwargs
Additional command execution options.

Returns

List of dictionaries containing Name, Length, LastWriteTime, and Attributes for each item in the directory. Returns empty list for empty directories.

def md5(self, alias: str, path: str, **kwargs) ‑> str

Get MD5 hash of file.

Args

alias
Session alias for the connection.
path
Path to the file.
**kwargs
Additional command execution options.

Returns

MD5 hash string.

def owner(self, alias: str, path: str, **kwargs) ‑> str

Get file or directory owner.

Args

alias
Session alias for the connection.
path
Path to query.
**kwargs
Additional command execution options.

Returns

Owner name as a string.

def permissions(self, alias: str, path: str, **kwargs) ‑> dict

Get file or directory permissions (ACL information).

Args

alias
Session alias for the connection.
path
Path to query.
**kwargs
Additional command execution options.

Returns

Dictionary containing ACL information including Owner, Group, AccessToString, and detailed Access information with FileSystemRights, AccessControlType, IdentityReference, IsInherited, InheritanceFlags, and PropagationFlags.

def size(self, alias: str, path: str, **kwargs) ‑> str

Get file size in bytes.

Args

alias
Session alias for the connection.
path
Path to the file.
**kwargs
Additional command execution options.

Returns

File size in bytes as a string. Note
Only works with files, not directories.