Python utility for removing all subdirectories of a directory while preserving all the files located in the subdirectories.
Project description
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
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
Built Distribution
File details
Details for the file rmdirs-0.1.1.tar.gz
.
File metadata
- Download URL: rmdirs-0.1.1.tar.gz
- Upload date:
- Size: 4.1 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.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3c9e8dfc4d8a66a9b161d5ec4ae1a6be82a3dfeec079c1b6afe5a1e94f9b5ea |
|
MD5 | 726f017aed970ee048f9615ba1200885 |
|
BLAKE2b-256 | f67aad211412186f9e092475b58d1791ebe5f18d6887861be12c6aa1883981ed |
File details
Details for the file rmdirs-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: rmdirs-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.4 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.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7597efd185eecf6d078cd7a1e65547e265c549c6548ad89cbb744fe63983605 |
|
MD5 | 971d5338b513c93f735f87d4fd7c9ad3 |
|
BLAKE2b-256 | 050b58946c6b762c813d0044fb352d23ab58ab6768aba11c30739d0f541087fd |