Package for directories, files & paths management utilities.
Project description
File Management Utilities (fmutils)
For easily accessing and managing large number of files and dirs in ML datasets.
Implemented Functions
class DirectoryTree
generator.
generates a dir tree displaying the full structure of the root dir, showing all the sub-dirs and the files.
Parameters:- root_dir – absolute/relative path to root directory containing all files.
- dir_only – whether to only show sub-dirs in the dir-tree (excluding the files inside of each dir and sub-dir, good for getting an overview of large databases). The default is False.
- write_tree – write the full dir-tree in a txt file in current working dir. The default is True.
get_all_files(main_dir, sort=True)
returns the list of all files inside the root dir.
Parameters:- main_dir – absolute/relative path to root directory containing all files.
- sort – wether to sort the output lost in Alphabetical order.
get_all_dirs(main_dir, sort=True)
returns the list of all the sub-dirs inside the root dir.
Parameters:- main_dir – absolute/relative path to root directory containing all files.
- sort – wether to sort the output lost in Alphabetical order.
get_num_of_files(main_dir)
counts the number of files inside each sub-dir of the root.
Parameters:- main_dir – absolute/relative path to root directory containing all files.
A Dictionary containing follwoing keys/info;
get_basename(full_path, include_extension=True)
returns the basename of the file or the dir name at end of given path. In case of file you can choose wether to include the extension or not.
Parameters:- full_path – absolute/relative path to root directory containing all files.
- include_extension – if the input full_path leads to file the by default the the file's extension in included in output string.
get_random_files(main_dir, count=1)
returns a list of randomly selected files from the root dir.
Parameters:- main_dir – absolute/relative path to root directory containing all files.
- count – the number of files to get from root and its sub-dir.
del_all_files(main_dir, confirmation=True)
delete all files from root and all its sub-dirs.
Parameters:- main_dir – absolute/relative path to root directory containing all files.
- confirmation – confirm before deleting the files.
Usage
from fmutils.directorytree import DirectoryTree
dt = DirectoryTree(root_dir='..Downloads/test_dir', dir_only=False,
write_tree=True)
dt.generate()
output
directory tree file saved at
../dir_tree.txt
inside text file
C:\Users\talha\Downloads\test_dir\
│
├── dir1\
│ ├── ADE_train_00000983.jpg
│ ├── ADE_train_00000984.jpg
│ ├── ADE_train_00000994.png
│ ├── ADE_train_00000995.jpg
│ ├── ADE_train_00001021.jpg
│ ├── ADE_train_00001022.jpg
│ ├── ADE_train_00001022.png
│ └── redme.txt
│
├── dir2\
│ ├── sub_dir1\
│ │ └── sub_sub_dir1\
│ │ ├── housing.csv
│ │ ├── iris.csv
│ │ ├── mnist_test_300.csv
│ │ └── mnist_train_3000.csv
│ │
│ │
│ └── sub_dir2\
│
│
├── dir3\
│ ├── index_ade20k.mat
│ ├── _annotations.txt
│ ├── __9t72HlzHdWWgOQSZVv8A.json
│ ├── __IoBfs3I6vB5ND-vqXK1A.json
│ ├── __KhdlKlVCeDQzVU2iyqYA.json
│ ├── __kprvedRGmbZJIfLBNq_w.json
│ ├── __VyXRQL8yDPkUBPTpW19A.xml
│ ├── __xaqDe9h8QfOyxTt0224Q.xml
│ ├── __Y8BcLJ1fhqwMARVgPg7Q.xml
│ ├── __YtZD5n9fhOMe-rzQa5oA.xml
│ └── __ZqCAIYS0qHpupUQoUuEQ.xml
│
└── dir4\
└── sub_dir1\
├── demo.py
└── Mapillary Vistas Research Edition License.pdf
from fmutils import fmutils as fmu
d_list = fmu.get_all_dirs(main_dir = 'C:/Users/talha/Downloads/test_dir', sort=True)
print(d_list)
For further details and more examples visit my github
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
File details
Details for the file fmutils-0.1.3.tar.gz
.
File metadata
- Download URL: fmutils-0.1.3.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.1.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d266099cb93f7f4343a3aaa71f00430953acfa6f359c27a1962705561da0fea |
|
MD5 | 34f4a58f9d165cac3fbe5ca13a3d14e7 |
|
BLAKE2b-256 | e978fc0146863b88b770ebace11ba5294b6b372d5d7404ecdff78dae1954a57d |