os.windows.fs

Module Contents

Classes

WithOpenFile

NTFile

Class to manipulate Win32 paths.

Attributes

logger

os.windows.fs.logger
class os.windows.fs.WithOpenFile(desired_access: int | None = None, shared_access: int | None = None, open_options: int | None = None)
__call__(f: collections.abc.Callable) Any
class os.windows.fs.NTFile(filename: str, parent: NTFile | None = None)

Class to manipulate Win32 paths.

Variables:
  • path – the full pathname

  • nt_filename – UnicodeString object representing either the full path or the basename of the file (when inititialized using a parent object)

  • handle – handle to the file. It is set to None if no call to open has been done

  • io_status – structure returned by most of low level API call

  • basic_info – ObjectAttributes object associated with the file

property volume_path: str

Retrieve path to the volume containing the file.

Returns:

path to a windows volume after junction resolution

Raise:

NTException

property uid: int

Retrieve the ID of the file.

On NTFS system we are sure that this ID is unique on the given volume

Returns:

the uid

Raise:

NTException

property is_dir: bool

Check if file is a directory.

Note that read_attributes methods should be called at least once otherwise the function will return False.

Returns:

True if the file is a directory, False otherwise

property is_readonly: bool

Check if file is readonly.

Note that read_attributes methods should be called at least once otherwise the function will return False.

Returns:

True if readonly, False otherwise

property trash_path: str

Return path in which the file can move safely for deletion.

On NTFS filesystem we are sure that the path is unique and thus that no existing file can exist at that location.

Returns:

a path

property is_dir_empty: bool

Check if dir is empty.

Returns:

True if the directory is empty. If not empty return False and set is_dir_empty_last_seen_file attribute to the first file found in the directory.

Raise:

NTException

__str__() str

Return str(self).

open(desired_access: int | None = None, shared_access: int | None = None, open_options: int | None = None) None

Open file.

Parameters:
  • desired_access – desired access (see e3.os.windows.native_api.Access)

  • shared_access – sharing parameters (see e3.os.windows.native_api.Shared)

  • open_options – open options (see e3.os.windows.native_api.OpenOptions)

close() None

Close file.

If a call has been done to open, close the handle associated with the file and reset the handle to None.

read_attributes_internal() None

Retrieve file basic attributes (internal function).

The function is used internally to check file basic attributes (kind of entry and windows attributes such as readonly). Retrieved attributes are stored in basic_info Python attribute. It requires less rights than the read_attributes method.

read_attributes() e3.os.windows.native_api.FileInfo.Basic

Retrieve file basic information.

It updates the basic_info attribute including timestamp information

Raise:

NTException

write_attributes() None

Update file attributes.

Raise:

NTException

rename(filename: str, replace: bool = False) None

Move file.

Parameters:
  • filename – target location

  • replace – if True replace the target file if it exists

Raise:

NTException

move_to_trash() None

Move file to trash location.

Raise:

NTException

dispose() None

Remove the file (low level).

The remove is effective on call to close method

iterate_on_dir(fun: collections.abc.Callable, default_result: Any = None) Any

Iterate on directory.

Parameters:
  • fun – function called on each entry (. are .. are skipped)

  • default_result – default return value

Returns:

last return value or fun or default_result

Remove file safely.

Raise:

NTException