os.fs¶
Low-level file manipulation.
All function here should be platform independent, should not involve globbing or logging (unless in case of unexpected failure).
Attributes¶
Classes¶
Functions¶
|
Change current directory. |
|
Chmod with interface similar to Unix tool. |
|
Disk space available on the filesystem containing the given path. |
|
Provide a safe unlink function on windows. |
|
Force file removing, changing permissions if first attempt failed. |
|
Transform an |
|
Return the maximum length for a path. |
|
Move a file. |
|
Get target path of a symlink. |
|
Update file access and modification times. Create the file if needed. |
|
Convert path to Unix/Cygwin format. |
|
Locate executable. |
Module Contents¶
- os.fs.CYGPATH_MATCH: re.Pattern[str]¶
- class os.fs.OSFSError¶
Bases:
e3.error.E3Error
- os.fs.logger¶
- os.fs.cd(path: str | pathlib.Path) None¶
Change current directory.
- Parameters:
path – directory name
- Raises:
OSFSError – in case of error
- os.fs.chmod(mode: str, filename: str | pathlib.Path) 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 | pathlib.Path) int¶
- os.fs.df(path: str | pathlib.Path, 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,usedandfreeattributes. Each attribute is an int representing Mo.
- os.fs.__safe_unlink_func() tuple[collections.abc.Callable[[str | pathlib.Path], None], collections.abc.Callable[[str | pathlib.Path], None]]¶
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 | pathlib.Path) None¶
Force file removing, changing permissions if first attempt failed.
- Parameters:
path – path of the file to remove
- os.fs.ldd_output_to_posix(ldd_output: str) str¶
Transform an
lddoutput to POSIX paths only.This method does not have any impact when the
lddoutput has been executed on a Unix host, because paths are already POSIX there.It applies only to
lddoutputs on Windows, where the paths starting with /c/, /mnt/c/ or /cygdrive/c/ are modified to C:/.For instance,
/c/WINDOWS/System32/ntdll.dllis transformed toC:/WINDOWS/System32/ntdll.dll.Note
The transformation is made on strings only to minimize the call the
cygpath. If a file path is found, all its occurrences are replaced by its POSIX value.- Parameters:
ldd_output – The output of an
lddcall to transform to contain only POSIX paths.- Returns:
An
lddoutput with POSIX paths only.
- os.fs.max_path() int¶
Return the maximum length for a path.
- Returns:
the maximum length
- os.fs.mv(source: str | pathlib.Path, target: str | pathlib.Path) None¶
Move a file.
- Parameters:
target – file to move
source – target file or directory
- os.fs.readlink(filename: str | pathlib.Path) str¶
Get target path of a symlink.
Equivalent of os.readlink with support for WSL Windows links.
- Parameters:
filename – path containing a symlink
- Returns:
target of the symlink
- os.fs.touch(filename: str | pathlib.Path) None¶
Update file access and modification times. Create the file if needed.
- Parameters:
filename – file to update
- os.fs.unixpath(path: str | pathlib.Path) 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 | pathlib.Path, 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