Skip to main content

Rename or remove files in a directory using an editor

Project description

Motivation

If you want to rename files in a directory, things get really cumbersome if:

  • the name modifications are not easily automatable (e.g. spelling mistakes)

  • file names contain spaces / special characters (when using a shell)

  • you have to rename a lot of files (when using a GUI)

  • you would need to use temporary files (e.g. mv a tmp ; mv b a ; mv tmp b)

  • etc.

This script launches a used-defined text editor with a temporary file, where every line is a filename in the directory. This enables the user to rename (edit a line) or delete (blank line) entries. After saving and exiting the editor, the script checks the file for consistency, detects rename loops and finally performs the changes.

News

3.0.0

2021-03-29

Require Python 3.6 (no new features, just usage of “try … from”)

2.1.0

2017-05-01

Support renaming of intermediate dirs in recursive mode, drop --safe mode, small bugfixes

2.0.0

2017-03-22

Bugfixes, Python 3 support, -o and -L option, extensive test suite

1.1

2010-11-21

Bugfixes

1.0

2010-05-06

First working version

Examples

Rename non-hidden files in the current directory:

dir_edit

Rename mp3 files in the music directory using gedit:

dir_edit -e gedit ~/Music ~/Music/*.mp3

Review changes before executing them:

dir_edit -vd -L log.txt
view log.txt
sh -e log.txt

Rename pictures with maximum directory depth 2:

find pics -maxdepth 2 -type f -iregex ".*\.\(jpg\|png\)" > file_list
dir_edit -i file_list

Usage

dir_edit [OPTION]... [DIR] [FILES]...

  DIR        directory to edit (default: current directory)
  FILES      limit to these filenames (default: all non-hidden in directory)

Some options:

  -e CMD, --editor=CMD       use CMD to edit dirfile (default: $EDITOR or vi)
  -d, --dry-run              don't perform any file system modifications
  -v, --verbose              output filesystem modifications to stdout
  -L FILE, --logfile FILE    path to logfile for verbose mode (default: stdout)
  -i FILE, --input FILE      FILE containing paths to be edited

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

dir-edit-3.0.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

dir_edit-3.0.0-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file dir-edit-3.0.0.tar.gz.

File metadata

  • Download URL: dir-edit-3.0.0.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.4.2 requests/2.25.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for dir-edit-3.0.0.tar.gz
Algorithm Hash digest
SHA256 eec517ea9805d13232ba4ae02fbf6467e2c6c105d10b59508478324beb67bf51
MD5 e0d86003c37f679c5646972ffdbd550e
BLAKE2b-256 43d7ec51a65da5e9a9fa19b9309864a103332cc0ea9f16c9bb06825514a3ce29

See more details on using hashes here.

File details

Details for the file dir_edit-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: dir_edit-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.4.2 requests/2.25.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for dir_edit-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a555f0d966d9bc28e100c6aba2d927d898b116c07a303426e57b6558e2e44330
MD5 18f0acd586c862217256a3447bdcb562
BLAKE2b-256 9d6f61991454f7808a0e688907929e999bbbaa9be19f944888f353534d164e8d

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