rmdirs
Rmdirs is a python utility package for removing subdirectories. The files located in the subdirectories are preserved and they are moved into the root directory. The moved files are renamed according to the relative path from the root directory to the subdirectory they are located in. Any '\' and '/' separators on the relative path are replaced by the separator character. The separator character is '_' by default.
If there are any naming conflicts that arise as a result of renaming moved files then a space and an integer in brackets is appended to the file name as follows:
'target/file/path.ext'
=> 'target/file/path' + ' (i)' + '.ext'
=> 'target/file/path (i).ext'
Instalation
You can use pip to install rmdirs.
pip install rmdirs
Usage
You can call rmdirs as a script with the -m module call.
python -m rmdirs -r root_dir
python -m rmdirs -r root_dir -s '_'
Or you can import rmdirs and use the remove function.
import rmdirs
rmdirs.remove(root_dir, separator='_')
Examples
Input directory structure:
root_dir/
|-- file1.ext
|-- 1/
| |-- a/
| | |-- i/
| | | |-- file1.ext
| | | |-- file2.ext
| | |-- ii/
| | | |-- file1.ext
| | |-- iii/
| |-- b/
| | |-- i/
| | |-- ii/
| | | |-- file1.ext
| | | |-- file2.ext
| | | |-- file3.ext
|-- 2/
| |-- a/
| |-- b/
| | |-- i/
|-- 3/
| |-- a/
| |-- b/
| | |-- file1.ext
| |-- c/
|-- 4/
| |-- file1.ext
Resulting directory structure:
root_dir/
|-- 1_a_ii_file1.ext
|-- 1_a_i_file1.ext
|-- 1_a_i_file2.ext
|-- 1_b_ii_file1.ext
|-- 1_b_ii_file2.ext
|-- 1_b_ii_file3.ext
|-- 3_b_file1.ext
|-- 4_file1.ext
|-- file1.ext
Input directory structure:
root_dir/
|-- 1_a_file.ext
|-- 1_file.ext
|-- 1/
| |-- a_file.ext
| |-- file.ext
| |-- a/
| | |-- file.ext
Resulting directory structure:
root_dir/
|-- 1_a_file (1).ext
|-- 1_a_file (2).ext
|-- 1_a_file.ext
|-- 1_file (1).ext
|-- 1_file.ext
Release files for rmdirs 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rmdirs-0.1.1.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rmdirs-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.5 kB
Release files / rmdirs-0.1.1.tar.gz
| Download URL | rmdirs-0.1.1.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a3c9e8dfc4d8a66a9b161d5ec4ae1a6be82a3dfeec079c1b6afe5a1e94f9b5ea
|
|
BLAKE2b-256 checksum How to use checksums |
f67aad211412186f9e092475b58d1791ebe5f18d6887861be12c6aa1883981ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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.3
|
Release files / rmdirs-0.1.1-py3-none-any.whl
| Download URL | rmdirs-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7597efd185eecf6d078cd7a1e65547e265c549c6548ad89cbb744fe63983605
|
|
BLAKE2b-256 checksum How to use checksums |
050b58946c6b762c813d0044fb352d23ab58ab6768aba11c30739d0f541087fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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.3
|