Skip to main content

Extends the functionalities of Pythion Pathlib

Project description

Pathlib Extensions

example workflow

Add convenience methods to Python Pathlib via monkey patching.

Installation

Pathlibext is available in PyPI. To Install it use pip:

pip install pathlibext

Usage

Just import pathlibext once and Path object will be extended with a series of convenience methods:

from pathlib import Path
import pathlibext  # pylint: disable=unused-import


if __name__ == '__main__':
    tmp = Path.tmpdir()  # from pathlibext
    files = [
        tmp / "1" / "a.txt",
        tmp / "1" / "b.txt",
        tmp / "2" / "a.txt",
        tmp / "2" / "b.txt",
    ]
    for f in files:
        f.parent.mkdir(exist_ok=True)
        f.touch()
    for d in tmp.find(type_="d", name="2"):  # from pathlibext
        print(f"removing {d}...")
        d.rmtree()  # from pathlibext
    tmp.rmtree()

List of added methods

  • Unix-like find: Path(".").find(type_f, name="*.py", maxdepth=4)
  • File name match: Path("/tmp/Something.txt).match("S*.txt)
  • File name matchcase: Path("/tmp/Something.txt).matchcase("s*.txt)
  • Remove non-empty directory tree: Path("/tmp/something/").rmtree()
  • Copy: Path("tmp/something.txt).copy("~/tmp")
  • Copy preserve metadata: Path("tmp/something.txt).copy_preserve_metadata("~/tmp")
  • Move: Path("tmp/something.txt).move("~/tmp")
  • File size: Path("tmp/something.txt).size()
  • File access time: Path("tmp/something.txt).access_time()
  • File modification time: Path("tmp/something.txt).modification_time()
  • File creation time (Windows only): Path("tmp/something.txt).creation_time()
  • File metadata change time (Posix only): Path("tmp/something.txt).metadatachange_time()
  • System temporary directory as Path: Path.systmpdir()
  • Create temporary directory as Path in existing directory: Path("tmp").tmpdir_in()
  • Create temporary directory as Path: Path().tmpdir()
  • Current file path: Path.current_file_path()
  • Current file directory: Path.current_file_dir()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pathlibext-0.0.2-py3-none-any.whl (5.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page