Skip to content
rdavidPublic

About

Normalizes file and directory names to lowercase letters, digits, and hyphens

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

351 Commits

Folders and files

Repository files navigation

Renamr

About

renamr normalizes file and directory names. It rewrites them with lowercase English letters, digits, and hyphens in place of spaces and other symbols. The result is a set of names that are safe to type, sort, and share across file systems. Each name passes through a pipeline of steps:

  • It lowercases letters and transliterates Cyrillic and other accented characters to English.

  • It replaces spaces, punctuation, and symbols such as & and $ with hyphens or words.

  • It rewrites dates such as 2020-11-02 as 20201102. It reads an ambiguous date day first, so 12-02-2022 becomes 20220212.

  • It trims stray hyphens and keeps file extensions intact.

  • It truncates names to 143 characters to fit encrypted file systems.

Optional steps cut, replace, or prepend text, add the modification time, and walk directories recursively. renamr only previews the changes by default. It renames nothing until you pass --act. The project has a website.

Install

The tool runs on macOS, GNU/Linux, and other Unix-like operating systems, as well as Windows. It is packaged as a Ruby gem and requires Ruby 3.2 or later. If your platform lacks a suitable Ruby, see Installing Ruby.

Install the gem with:

gem install renamr

Or install it with Homebrew from the rdavid tap:

brew install rdavid/tap/renamr

Usage

renamr [options]
  -a, --act              Performs actual renaming.
  -c, --cut pos,len      Removes len characters starting at pos.
  -d, --dir dir          Sets the directory to process.
  -l, --lim              Limits file name length.
  -m, --mod              Prepends file modification time.
  -p, --prepend str,beg  Prepends a string.
  -r, --rec              Processes directories recursively.
  -s, --src src          Sets the string to replace.
  -t, --dst dst          Sets the replacement string.
  -v, --version          Shows the version.
  -w, --wid wid          Sets the output table width.

renamr processes the current directory unless --dir names another one. It prints a table of old and new names and leaves the files untouched:

renamr --dir ~/Downloads
+--------------------------------------------------------------+
|                         ~/Downloads                          |
+-------------------------------+------------------------------+
|              src              |             dst              |
+-------------------------------+------------------------------+
| IMG 0042 Beach Trip.JPG       | img-0042-beach-trip.jpg      |
| Meeting Notes 2024-07-15.txt  | meeting-notes-20240715.txt   |
| Old Photos                    | old-photos                   |
| Tom & Jerry.mp4               | tom-and-jerry.mp4            |
| Отчёт за май.docx             | otchjot-za-may.docx          |
+-------------------------------+------------------------------+
| Test: 5 moved in less than a second.                         |
+--------------------------------------------------------------+

Review the table, then repeat the command with --act to apply it:

renamr --dir ~/Downloads --act

Add --rec to descend into subdirectories as well.

The optional steps run before the normalization. Each example below shows its result for IMG 0042 Beach Trip.JPG:

# Replaces Beach with Sea, case-sensitively: img-0042-sea-trip.jpg.
renamr --src Beach --dst Sea

# Removes 4 characters from position 1: 0042-beach-trip.jpg.
renamr --cut 1,4

# Prepends a string at position 0: 2024-img-0042-beach-trip.jpg.
renamr --prepend 2024-,0

# Prepends the modification date: 20261108-img-0042-beach-trip.jpg.
renamr --mod

# Shortens only the names longer than 143 characters.
renamr --lim

License

renamr is copyright David Rabkin and is available under the Zero-Clause BSD license.

About

Normalizes file and directory names to lowercase letters, digits, and hyphens

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages