torchoutil.pyoutil.os module

get_num_cpus_available() int[source]

Returns the number of CPUs available for the current process on Linux-based platforms.

On Windows and MAC OS, this will just return the number of logical CPUs on this machine. If the number of CPUs cannot be detected, returns 0.

safe_rmdir(
root: str | Path,
*,
rm_root: bool = True,
error_on_non_empty_dir: bool = True,
followlinks: bool = False,
dry_run: bool = False,
verbose: int = 0,
) Tuple[List[str], List[str]][source]

Remove all empty sub-directories.

Args:

root: Root directory path. rm_root: If True, remove the root directory too if it is empty at the end. defaults to True. error_on_non_empty_dir: If True, raises a RuntimeError if a subdirectory contains at least 1 file. Otherwise it will ignore non-empty directories. defaults to True. followlinks: Indicates whether or not symbolic links shound be followed. defaults to False. dry_run: If True, does not remove any directory and just output the list of directories which could be deleted. defaults to False. verbose: Verbose level. defaults to 0.

Returns:

A tuple containing the list of directories paths deleted and the list of directories paths reviewed.

tree_iter(
root: str | Path,
*,
exclude: str | Pattern | Iterable[str | Pattern] = (),
space: str = '    ',
branch: str = '│   ',
tee: str = '├── ',
last: str = '└── ',
max_depth: int = 9223372036854775807,
followlinks: bool = False,
) Generator[str, Any, None][source]

A recursive generator, given a directory Path object will yield a visual tree structure line by line with each line prefixed by the same characters

Based on: https://stackoverflow.com/questions/9727673/list-directory-tree-structure-in-python