Python tools to find last file/folder number in a int indexed file/folder with specified extension, prefix and/or suffix. Also allows to create next folder, e.g if dir contains train_00 and train_01, it creates train_02
Project description
filenumutils
Python tools to find last file/folder number in a int indexed file/folder with specified extension, prefix and/or suffix. Also allows to get/create next folder, e.g if dir contains train_00
and train_01
, it creates train_02
.
Installation
Simply install using pip
pip install filenumutils
Usage
Assuming the current working directory has the following structure
current_dir ├─ train_00 ├─ train_01 ├─ train_03 ├─ train_04 ├─ model_00.py ├─ model_01.py └─ model_02.py
Get Last Folder / File Number
from filenumutils import get_last_folder_number, get_last_file_number
get_last_folder_number(prefix="model_") # Output: 4
get_last_file_number(prefix="train_") # Output: 2
If no such file/folder with given prefix exists, it outputs -1
Get Next Folder / File Name
from filenumutils import get_next_file, get_next_folder
get_next_file(prefix="model_") # Output: model_03.py
get_next_folder(prefix="test_") # Output: test_00
get_next_folder(prefix="train_", create=True) # Output: train_05 (Folder is created)
If no such folder with given prefix exists, it outputs prefix_00
.
Also, it will automatically stick to the existing numbering pattern.
For eg, if the folders were [train_0000
, train_0001
],
get_next_folder(prefix="train_", create=True) # Output: train_0000 (Folder is created)
More Options
Attribute | Default | Description |
---|---|---|
path |
Current Directory | Do operations in the given directory |
prefix |
"" | Match only files with given prefix |
suffix |
"" | Match only files with given extension/suffix |
default_number_width |
2 | When no numbering pattern is found, output number will be default_number_width digits |
full_path |
True | By default, returns new_folder_name . If True, returns path/new_folder_name . |
Contributing
Pull requests are very welcome.
- Fork the repo
- Create new branch with feature name as branch name
- Check if things work with a jupyter notebook
- Raise a pull request
Licence
Please see attached Licence
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file filenumutils-0.1.2.tar.gz
.
File metadata
- Download URL: filenumutils-0.1.2.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02cc266dafaa50973feff646f9884ffe53194ab392309625f293a9a03ceb1451 |
|
MD5 | 4f8218cd660030052bf85dbfceb75ac4 |
|
BLAKE2b-256 | ba707e2dfa66176089ef4e96805a9ad1f33d4b4ded2563c93d97d2e8d8545d57 |
File details
Details for the file filenumutils-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: filenumutils-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e6261af08946f1d2a07ea231b966a20a719f241226e4cdbba944e30667d3314 |
|
MD5 | b82e62df8f62ebe921b8779e57066352 |
|
BLAKE2b-256 | 153106e32c633b6ee76c27d9ff34a2fe03e9182736af875fc5967e86803f022a |