os.windows.fs

Attributes

logger

Classes

WithOpenFile

NTFile

Class to manipulate Win32 paths.

Module Contents

os.windows.fs.logger
class os.windows.fs.WithOpenFile(desired_access: int | None = None, shared_access: int | None = None, open_options: int | None = None)
desired_access = None
shared_access = None
open_options = None
__call__(f: collections.abc.Callable) Any
class os.windows.fs.NTFile(filename: str | pathlib.Path, 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

handle: ctypes.wintypes.HANDLE | None = None
io_status
basic_info
attr
desired_access
shared_access
open_options
is_dir_empty_last_seen_file: str | None = None
__str__() str
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.

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 reparse_tag: int

Find the reparse point tag for a given file.

Returns:

the tag as int. 0 is returned if not a reparse point

Get target of a WSL link (also used by Cygwin).

Returns:

the link target

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

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 is_reparse_point: bool

Check if a given file is a reparse point.

Returns:

True if the file is a reparse point, False otherwise

Check whether a given file is a symlink or not.

Returns:

return True for all kind of symlinks (native and WSL).

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

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

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

Remove file safely.

Raise:

NTException