Easy to use file search and file path management in python.
Project description
pyfilemanager
Easy to use file search and file path management in python.
Installation
pip install pyfilemanager
Usage
Quickstart
from pyfilemanager import FileManager
fm = FileManager(r'C:\videos')
fm.add('canon', '*Camera.avi', include='canon')
video_list = fm['video']
Long version
Consider the following directory structure
C:\videos
├── sony
│ ├── 142Camera.avi
│ ├── 143Camera.avi
│ ├── notes.txt
├── panasonic
│ ├── 151Camera.avi
│ ├── 143Camera.avi
│ ├── notes.txt
├── panasonic2
│ ├── 201Camera.avi
│ ├── 202.mp4
├── canon
│ ├── 51Camera.avi
│ ├── 40Camera.avi
│ ├── notes.txt
├── notes
│ ├── notes1.txt
│ ├── notes2.txt
- Import the FileManager class.
from pyfilemanager import FileManager
- Initialize the file manager.
fm = FileManager(r'C:\videos', exclude_hidden=True)
- Add files based on different inclusion and exclusion criteria. Use the include parameter to keep file paths that contain all of the supplied strings anywhere in the file path. Use the exclude parameter to disregard file paths that contain any of the supplied string anywhere in the file path.
fm.add('canon', '*Camera.avi', include='canon') # file path must contain canon fm.add('sony42', '*Camera.avi', include=['sony', '42']) # file path must contain sony AND 42 # grabs one file - sony\142Camera.avi fm.add('videos', ['*.avi', '*.mp4']) # add multiple conditions by supplying them as a list or tuple fm.add('panasonic', '*.avi', include='panasonic', exclude='panasonic2') # grab videos in the panasonic folder fm.add('notes', 'notes*.txt') # grab all notes fm.add('notes', 'notes*.txt', include='notes\\notes') # grab notes from the notes folder # this will overwrite the previous notes entry fm.add('notes', 'notes*.txt', exclude=['sony', 'panasonic', 'panasonic2', 'canon']) # achieves the same result as the previous line
- Retrieve file paths using a dict-like convention.
fm['canon'] # Retrieve by the tag 'canon' # Returns canon/40Camera.avi and canon/51Camera.avi fm['143Camera'] # When a tag is not found, retrieve file paths by the stem. # Returns panasonic/143Camera.avi and sony/143Camera.avi fm['20'] # If the key doesn't match a tag or a stem of a filename, do a loose-search to retrieve all entries where the tag is anywhere in the full path. # Returns panasonic2/201Camera.avi and panasonic2/202.mp4 all_videos = fm['videos']
- Add and retrieve in one line of code.
fm.add('canon', '*Camera.avi', include='canon')['canon'] # Note that the method returns the instance of the FileManager object.
- Retrieve all the added keys using fm.get_tags()
fm.get_tags() # returns a tuple ('canon', 'sony42', 'videos', 'panasonic', 'notes')
- Retrieve paths of all the added files.
fm.all_files
- Get a report of the number of files, and the occupied space.
fm.report()
2 canon files taking up 0.000 MB 1 sony42 files taking up 0.000 MB 8 videos files taking up 0.000 MB 2 panasonic files taking up 0.000 MB 5 txt files taking up 0.000 MB
License
Distributed under the MIT License. See LICENSE
for more information.
Contact
Project Link: https://github.com/praneethnamburi/pyfilemanager
Acknowledgments
This tool was developed as part of the ImmersionToolbox initiative at the MIT.nano Immersion Lab. Thanks to NCSOFT for supporting this initiative.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyfilemanager-0.1.1.tar.gz
(5.8 kB
view hashes)
Built Distribution
Close
Hashes for pyfilemanager-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e284218fba509b5ed2f4099a8b2ae92a2700ade4b5016b79a629f731a935d303 |
|
MD5 | e9a60181e78112c6b6f587aea507450d |
|
BLAKE2b-256 | ee03732ae2ce7ca62a1709adb1ee5af8bef27f0ab90c502750c2fb2536639f9e |