doFolder.fileSystem.tools module

Utility functions for file system operations.

This module provides helper functions for creating file system items, type checking, and converting between different file system representations.

Added in version 2.3.0.

doFolder.fileSystem.tools.createItem(path: str | Path, unExistsMode: UnExistsMode = UnExistsMode.WARN, errorMode: ErrorMode = ErrorMode.WARN, toAbsolute: bool = False, exceptType: ItemType | None = None) File | Directory

Create a file system item based on the given path.

Automatically detects whether the path points to a file or directory and creates the appropriate object. If the path doesn’t exist, behavior is controlled by unExistsMode parameter.

Parameters:
  • path (Pathable) – Path to the file or directory.

  • unExistsMode (UnExistsMode, optional) – Behavior when path doesn’t exist. Defaults to WARN.

  • errorMode (ErrorMode, optional) – Error handling mode. Defaults to WARN.

  • toAbsolute (bool, optional) – Convert path to absolute. Defaults to False.

  • exceptType (ItemType, optional) – Expected item type (FILE or DIR). Defaults to None.

Returns:

File or Directory object based on the path type.

Return type:

_classes.FileSystemItem

doFolder.fileSystem.tools.isDir(target: _classes.FileSystemItemBase) _tt.TypeIs[_classes.Directory]

Check if target is a directory.

Parameters:

target (_classes.FileSystemItemBase) – The file system item to check.

Returns:

True if target is a directory, False otherwise.

Return type:

bool

doFolder.fileSystem.tools.isFile(target: _classes.FileSystemItemBase) _tt.TypeIs[_classes.File]

Check if target is a file.

Parameters:

target (_classes.FileSystemItemBase) – The file system item to check.

Returns:

True if target is a file, False otherwise.

Return type:

bool

doFolder.fileSystem.tools.toFileSystemItem(fr: _classes.FileSystemItemLike) _classes.FileSystemItem

Convert FileSystemItemLike to FileSystemItem.

Parameters:

fr (_classes.FileSystemItemLike) – Object to convert (_classes.FileSystemItemLike).

Returns:

FileSystemItem object.

Return type:

_classes.FileSystemItem

Added in version 2.2.0.