Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ConquerProgramming1/pathlib_additions
Adds useful methods to the built-in pathlib.Path class.
https://github.com/ConquerProgramming1/pathlib_additions
Last synced: 7 days ago
JSON representation
Adds useful methods to the built-in pathlib.Path class.
- Host: GitHub
- URL: https://github.com/ConquerProgramming1/pathlib_additions
- Owner: ConquerProgramming1
- License: mit
- Created: 2019-03-27T20:39:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-10-10T12:57:02.000Z (about 2 years ago)
- Last Synced: 2024-08-01T15:29:49.968Z (3 months ago)
- Language: Python
- Size: 5.86 KB
- Stars: 2
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pathlib_additions
I create workflows that involve a huge number of file operations. For doing file operations I strongly recommend the built-in ``pathlib`` library. Before ``pathlib`` to work with files you had to deal with methods in three different libraries (at least) that were designed around the C/UNIX approach to file handling. Not Pythonic, to say the least.In Python 2 I used a third party libary called [Unipath](https://pypi.org/project/Unipath/) that put almost all the functionality I wanted in a ``Path`` object. In Python 3.4, the ``pathlib`` library was provided, which mostly mirrors ``Unipath``, but left a few things out.
So ``pathlib_additions`` are my additions to ``pathlib`` to make it do everything I want. You are welcome to use this and submit patches/requests/bugs.
To use it, do these imports:
from pathlib import Path
import pathlib_additions``pathlib_additions`` adds a number of methods to the Path object.
## write_content()
``write_content(content, encoding='utf-8', errors=None)``pathlib's ``write_text()`` method requires the destination directory to exist. ``write_content()`` creates the directory if necessary then uses ``write_text()`` to write out the text.
## directories()
The ``directories()`` method returns an iterator of directories in the Path.## files()
The ``files()`` method returns an iterator of files in the Path.## copy()
``copy(destination)``
Copies this path to the destination, which can be a Path object or string. Creates the destination directory if necessary.
## walk()
``walk(path_filter=None)``
Returns an iterator of all Paths in this path's directory structure.
If a ``path_filter`` function is specified, it is called for each item.## rmtree()
Removes all items under this path, including the path itself. Does *not* raise an exception if the path doesn't exist.*Library created by Ronald Hayden of [Conquer Programming](http://conquerprogramming.com)*