os.fs

Low-level file manipulation.

All function here should be platform indepenent, should not involve globbing or logging (unless in case of unexpected failure).

Module Contents

Functions

cd(→ None)

Change current directory.

chmod(→ int)

Chmod with interface similar to Unix tool.

df(…)

Disk space available on the filesystem containing the given path.

__safe_unlink_func(...)

Provide a safe unlink function on windows.

force_remove_file(→ None)

Force file removing, changing permissions if first attempt failed.

max_path(→ int)

Return the maximum length for a path.

mv(→ None)

Move a file.

touch(→ None)

Update file access and modification times. Create the file if needed.

unixpath(→ str)

Convert path to Unix/Cygwin format.

which(→ Any)

Locate executable.

Attributes

logger

exception os.fs.OSFSError(message: str | list[str], origin: str | None = None)

Bases: e3.error.E3Error

Exception raised by functions defined in E3.

os.fs.logger
os.fs.cd(path: str) None

Change current directory.

Parameters:

path – directory name

Raises:

OSFSError – in case of error

os.fs.chmod(mode: str, filename: str) int

Chmod with interface similar to Unix tool.

Parameters:
  • mode – should conform with posix specification for chmod utility (ex: +wx). See chmod man page for more information

  • filename – the target file

Returns:

the mode that has been set

os.fs.df(path: str) int
os.fs.df(path: str, full: Literal[True]) tuple

Disk space available on the filesystem containing the given path.

Parameters:
  • path – a path

  • full – if True return full disk information otherwise only space left.

Returns:

either space left in Mo or a py:meth:collections.namedtuple with total, used and free attributes. Each attribute is an int representing Mo.

Provide a safe unlink function on windows.

Note that all this is done to ensure that rm is working fine on Windows 7 and 2008R2. Indeed very often, deletion will fail with access denied error. The typical scenario is when you spawn an executable and try to delete it just afterward.

os.fs.force_remove_file(path: str) None

Force file removing, changing permissions if first attempt failed.

Parameters:

path – path of the file to remove

os.fs.max_path() int

Return the maximum length for a path.

Returns:

the maximum length

os.fs.mv(source: str, target: str) None

Move a file.

Parameters:
  • target – file to move

  • source – target file or directory

os.fs.touch(filename: str) None

Update file access and modification times. Create the file if needed.

Parameters:

filename – file to update

os.fs.unixpath(path: str) str

Convert path to Unix/Cygwin format.

Parameters:

path – path string to convert

Returns:

the converted path

On Unix systems this function is identity. On Win32 systems it removes drive letter information and replace \ by /.

os.fs.which(prog: str, paths: str | None = None, default: Any = '') Any

Locate executable.

Parameters:
  • prog – program to find

  • paths – if not None then we use this value instead of PATH to look for the executable.

  • default – default value to return if not found

Returns:

absolute path to the program on success, found by searching for an executable in the directories listed in the environment variable PATH or default value if not found