bagof.paths.Path
Bases: PurePathMixin, BaseWrapper
A path that works like pathlib.Path, local or in the cloud.
Make one from a path string, a URL, or any path object:
>>> from bagof.paths import Path
>>> p = Path("/data/sets/train.zarr")
>>> p.name
'train.zarr'
>>> p.parent
Path('/data/sets')
>>> (p / "chunks").suffix
''
Each method uses the underlying library when it can, builds the method
from simpler ones when it cannot, or raises UnsupportedPathOperation
when neither is possible.
Methods:
open
open(mode: str = 'r', buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str | None = None) -> IO[Any]
Open the path and return a file object, like :func:open.
read_text
read_text(encoding: str | None = None, errors: str | None = None, newline: str | None = None) -> str
Read the whole file as text.
write_text
write_text(data: str, encoding: str | None = None, errors: str | None = None, newline: str | None = None) -> int
Write data to the file as text, replacing any content.
glob
glob(pattern: str, *, case_sensitive: bool | None = None, recurse_symlinks: bool = False) -> Iterator[Self]
Yield the paths matching pattern under this directory.
rglob
rglob(pattern: str, *, case_sensitive: bool | None = None, recurse_symlinks: bool = False) -> Iterator[Self]
Like :meth:glob, recursively.
mkdir
Create a directory at the path.
touch
Create the file at the path, or update its modification time.
rmdir
rmdir(*, recursive: bool = False) -> None
Remove the directory at the path.
With recursive=True the whole tree is removed. The default is
non-recursive and stays safe even on drivers whose own rmdir
recurses by default (universal-pathlib).
copy
Copy this file or directory to target; return the new path.
copy_into
copy_into(target_dir: Any, *, follow_symlinks: bool = True, preserve_metadata: bool = False) -> Self
Copy into target_dir, keeping this path's name.
walk
walk(top_down: bool = True, on_error: Callable | None = None, follow_symlinks: bool = False) -> Iterator[tuple[Self, list[str], list[str]]]
Walk the tree, yielding (path, dirnames, filenames) per dir.
chmod
Change the file mode and permission bits.
symlink_to
Make this path a symbolic link to target.
link_to
link_to(target: Any) -> None
Make target a hard link to this path.
.. deprecated::
link_to takes the reverse argument order of
:meth:hardlink_to and was removed from pathlib in Python
3.12. Prefer :meth:hardlink_to; this is kept, and synthesized
where the driver dropped it, only for backward compatibility.
download_to
Download the path's contents to a local destination.