Package: regex-rename
regex-renameBulk rename tool based on regular expressions to rename multiple files at once.QuickstartRenaming multiple files at once:$ls# awful names:b45XDS-01.mp3QsEW2s-02.mp3VF7t6L-03.mp3

$regex-rename'-(\d+).mp3''\1_NeverGonnaGiveYouUp.mp3'--rename[2022-04-0909:19:15]DEBUGmatchingregularexpressionpatterntofiles:pattern=-(\d+).mp3replacement=\1_NeverGonnaGiveYouUp.mp3full_match=Falsedry_run=False[2022-04-0909:19:15]INFOrenamingfile:from=b45XDS-01.mp3to=01_NeverGonnaGiveYouUp.mp3[2022-04-0909:19:15]INFOrenamingfile:from=QsEW2s-02.mp3to=02_NeverGonnaGiveYouUp.mp3[2022-04-0909:19:15]INFOrenamingfile:from=VF7t6L-03.mp3to=03_NeverGonnaGiveYouUp.mp3[2022-04-0909:19:15]INFOfilesrenamed:renamed=3mismatched=0$ls# now we're talking:01_NeverGonnaGiveYouUp.mp302_NeverGonnaGiveYouUp.mp303_NeverGonnaGiveYouUp.mp3Installationpip3installregex-renameIt requires Python 3.7 (or newer) with pip.TutorialImagine you have 51 audio files with hideous names like this and you wish to rename them:Stanislaw+Lem+Invincible+(01).mp3->01 The Invincible.mp3Stanis▯aw+Lem+Invincible+(02 ).mp3->02 The Invincible.mp3Stanisław_Lem_Invincible (03) .mp3->03 The Invincible.mp3…Stanis▯aw+Lem+Invincible+(51).mp3->51 The Invincible.mp3Specifically, you want to place the episode number at the beginning.Step 1: MatchRegular Expressions can be tricky.
We figured out this pattern may match the files and extracts the episode number:(\d+).*mp3First, let's check this pattern in a dry run:regex-rename '(\d+).*mp3'Pay attention to the extracted regex groups.Step 2: ReplaceNow, we'd like to replace all files to a pattern:\1 The Invincible.mp3\1is a first group extracted by the matching pattern (episode number).Let's test it by adding the replacement pattern:regex-rename '(\d+).*mp3' '\1 The Invincible.mp3'Step 3: ExecuteAll above commands were just dry-run so that we could experiment with regex patterns.
Once we're sure that everything is matched correctly, we can append--renameflag,
which does the actual renaming:regex-rename '(\d+).*mp3' '\1 The Invincible.mp3' --renameFinally, files are named properly:01 The Invincible.mp302 The Invincible.mp303 The Invincible.mp3…51 The Invincible.mp3Beyond the Regexregex-renamealso supports some transformations not covered by regular expressions standard:Converting to lowercase by adding\Lbefore group number:regex-rename '([A-Z]+).mp3' '\L\1.mp3'eg.AUDIO.mp3toaudio.mp3Converting to uppercase by adding\Ubefore group number:regex-rename '([a-z]+).mp3' '\U\1.mp3'eg.audio.mp3toAUDIO.mp3Padding numbers with leading zeros by adding\P2,\P3, … (depending on padding length) before group number:regex-rename '(\d+).mp3' '\P2\1.mp3'eg.1.mp3to01.mp3Padding numbers with leading zeros by specifying--pad-toparameter:regex-rename '(\d+).mp3' '\1.mp3' --pad-to=2eg.1.mp3to01.mp3More examplesExtract season and episode numbers, eg.episode-02x05.mkvtoS02E05.mkv:regex-rename'(\d+)x(\d+)''S\1E\2.mkv'--renameSwap artist with title, eg.Echoes - Pink Floyd.mp3toPink Floyd - Echoes.mp3:regex-rename'([^-]+) - ([^-]+)\.mp3''\2 - \1.mp3'--renamePad leading zeros, eg.1.mp3to001.mp3:regex-rename'(\d+).mp3''\P3\1.mp3'--renameConvert to lowercase, eg.SONG.MP3tosong.mp3:regex-rename'(.+)''\L\1'--renameConvert to uppercase, eg.Tool.mp3toTOOL.mp3:regex-rename'(.+)\.mp3''\U\1.mp3'--renameAdd prefix, eg.Doors.mp3toThe Doors.mp3:regex-rename'(.+)''The \1'--full--renameChange extension, eg.Songbook.apktoSongbook.zip:regex-rename'(.+)\.apk''\1.zip'--renameTurn directories into prefixes and move files, eg.Pink Floyd/Echoes.mp3toPink Floyd - Echoes.mp3:regex-rename'(.+)/(.+).mp3''\1 - \2.mp3'--full--recursive--renameRename files in different directories, preserving their parent directories,
eg.app/logs/file-001.logtoapp/logs/file_001.txt:regex-rename'(.*)/file-([0-9]+).log''\1/file_\2.txt'--full--recursive--renameRename files piped from another command likefind,
eg.songs/Jimmi - Voodoo Child.mp3tosongs/Jimi - Voodoo Child.mp3:find-iname'*jimmi*'|regex-rename'(.*)/.* - (.*).mp3$''\1/Jimi - \2.mp3'--renameUsageEnterregex-renamefor help:$regex-renameregex-renamev1.3.0-Bulkrenametoolbasedonregularexpressionstorenamemultiplefilesatonce

Usage:
regex-rename[OPTIONS]PATTERN[REPLACEMENT]Arguments:PATTERN-Regexpatterntomatchfilenames[REPLACEMENT]-Replacementregexpatternforrenamedfiles.Use\1,\2syntaxtomakeuseofmatchedgroups

Options:--version-Printversioninformationandexit-h,--help[SUBCOMMANDS...]-Displaythishelpandexit-r,--rename-Doesactualrenamingfilesinsteadofjusttestingreplacementpattern--full-Enforcesmatchingfullfilenameagainstpattern--recursive-Searchdirectoriesrecursively--collate-Comparesourcefilenameswiththereplacednames--short-Printoutputinshort,lessverboseformatwithouttime--pad-toPAD_TO-Appliespaddingwithzeroswithgivenlengthonmatchednumericalgroups