Skip to main content

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 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rmdirs-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

rmdirs-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file rmdirs-0.1.0.tar.gz.

File metadata

  • Download URL: rmdirs-0.1.0.tar.gz
  • Upload date:
  • Size: 4.0 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

Hashes for rmdirs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 945fefa313ea2a003bece97a924228031680b7c63d194e0cc7ce2d9423203b8a
MD5 cb1bbd56a0e04426815592facc7ddde1
BLAKE2b-256 9fc2d874dbe495011a97e1081361f65600538c45be371a028e3e2e2c0c840fd1

See more details on using hashes here.

File details

Details for the file rmdirs-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rmdirs-0.1.0-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

Hashes for rmdirs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63996d7c8ae81472ae56c8d093e0376aff8f1546dcabf3892796493d4f167209
MD5 c2d9a4824f2c60d5ccaf7a7844dd03cc
BLAKE2b-256 8559875e8af8b0bb629efc27d2d727320bd511b0d87f9d3cc30ee0e995bd90de

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page