epath.Path#
- class etils.epath.Path(*args: str | os.PathLike)[source]
Bases:
pathlib.PurePosixPathAbstract base class for pathlib.Path-like API.
See [pathlib.Path](https://docs.python.org/3/library/pathlib.html) documentation.
- format(
- *args: Any,
- **kwargs: Any,
Apply str.format() to the path.
- exists() bool[source]
Returns True if self exists.
- is_dir() bool[source]
Returns True if self is a dir.
- is_file() bool[source]
Returns True if self is a file.
- iterdir() Iterator[etils.epath.abstract_path._T][source]
Iterates over the directory.
- listdir() list[etils.epath.abstract_path._T][source]
Lists files/folders in a directory.
Colab usage only!
This is not in the official pathlib.Path API, but on Colab, using list(path.iterdir()) is such a common pattern that it’s convenient to have it.
- glob(
- pattern: str,
Yields all matching files (of any kind).
- rglob(
- pattern: str,
Yields all matching files recursively (of any kind).
- walk(
- *,
- top_down: bool = True,
- on_error: collections.abc.Callable[[OSError], object] | None = None,
- expanduser() etils.epath.abstract_path._T[source]
Returns a new path with expanded ~ and ~user constructs.
- absolute() etils.epath.abstract_path._T[source]
Returns the absolute path.
- resolve(
- strict: bool = False,
Returns the absolute path.
- open(
- mode: str = 'r',
- encoding: str | None = None,
- errors: str | None = None,
- **kwargs: Any,
Opens the file.
- read_bytes() bytes[source]
Reads contents of self as bytes.
- read_text(encoding: str | None = None) str[source]
Reads contents of self as a string.
- stat() etils.epath.stat_utils.StatResult[source]
Returns metadata for the file/directory.
- mkdir(
- mode: int | None = None,
- parents: bool = False,
- exist_ok: bool = False,
Create a new directory at this given path.
- rmdir() None[source]
Remove the empty directory at this given path.
- rmtree(missing_ok: bool = False) None[source]
Remove the directory, including all sub-files.
- unlink(missing_ok: bool = False) None[source]
Remove this file or symbolic link.
- write_bytes(data: bytes) int[source]
Writes content as bytes.
- write_text(
- data: str,
- encoding: str | None = None,
- errors: str | None = None,
Writes content as str.
- touch(mode: int = 438, exist_ok: bool = True) None[source]
Create a file at this given path.
- rename(
- target: str | os.PathLike,
Renames the path.
- replace(
- target: str | os.PathLike,
Overwrites the destination path.
- copy(
- dst: str | os.PathLike,
- overwrite: bool = False,
Copy the current file to the given destination.