Package for easily accessing and managing large number of files and dirs (e.g. in ML datasets).
Project description
File Management Utilities (fmutils)
For easily accessing and managing large number of files and dirs in ML datasets.
Updates
version 0.1.4 includes some more functions
rename_wrt_dirname
filename_replacer
plot_data_dist
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.
rename_wrt_dirname(main_dir)
Change the names of all files inside the main_dir w.r.t their sub_dir names.
Parameters:- main_dir – absolute/relative path to root directory containing all files.
file_name_replacer(data_dir, new_name, name2replace)
Changes the names of all files inside a dir by replacing the specific strings in old file name with new ones, specified via 2 input lists.
Parameters:- main_dir – absolute/relative path to root directory containing all files.
- new_name – list containing the new names which will replace the old ones..
- name2replace – list containing the strings which will be replaced wiht new ones.
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.
plot_data_dist(main_dir)
Plots the bargaph showing number of files in all the sub dir of main dir.
Parameters:- main_dir – main directory which contains all the classes.
Usage
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.5.tar.gz
.
File metadata
- Download URL: fmutils-0.1.5.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 602f78372f8bd62ccaaf8479efcdfeed9952f3ec4c1485a3f28ac946bcb07e10 |
|
MD5 | 0413b91ab495ffe40e89a920b3da8ca4 |
|
BLAKE2b-256 | 921e9dfec11d19133582984ef6e2a420e50372388736b7f5afdd3c757485140a |