File Renaming Using a List of Names

Discuss anything related to portable freeware here.
Post Reply
Message
Author
User avatar
juverax
Posts: 369
Joined: Mon Jun 11, 2018 5:19 am

File Renaming Using a List of Names

#1 Post by juverax »

I was looking for a utility that can rename files using a list of names stored in a text file (one name per line).
It is something that AntRenamer ( https://www.portablefreeware.com/index.php?id=66 ) can do.
Go to "Actions", and in the list of actions AntRenamer can perform, there is the option "Take Names from List".

In addition I found on the internet a DOS Script that does exactly the same thing, which is nice if you don't have AntRenamer.

The script assumes that
- you create a text file (with the extension ".bat) with the script below. Name the script file whatever name you like, e.g renamenow.bat
- the script file, the files you want to rename, and the text file with the new names (in our example this file is named: "list.txt") are placed in the same folder
- the files you want to rename have all the same extension (MP3 in this example)
- the list of names is in a text file named list.txt (one name per line)
- the number of files to rename is the same as the number of lines in list.txt
- the names in list.txt will be appended to the original name
- double-click on renamenow to execute the batch

EXAMPLE
You have the following 5 original files:
Marching Band CD1_Part1.mp3
Marching Band CD1_Part2.mp3
Marching Band CD1_Part3.mp3
Marching Band CD1_Part4.mp3
Marching Band CD1_Part5.mp3

Content of list.txt
Alabama
Berkshire
Carolina
Delaware
Esperanza

Output: the 5 files are renamed as follow:
Marching Band CD1_Part1Alabama.mp3
Marching Band CD1_Part2Berkshire.mp3
Marching Band CD1_Part3Carolina.mp3
Marching Band CD1_Part4Delaware.mp3
Marching Band CD1_Part5Esperanza.mp3

This is probably NOT EXACTLY what you wanted, but it is very close, and a simple file renamer can beautify the new names.


Here is the Script (slightly modified from the original):

::CREDIT: https://stackoverflow.com/questions/200 ... -text-file
@ECHO OFF &SETLOCAL ENABLEDELAYEDEXPANSION
<list.txt (
for /f "tokens=* delims=* " %%a in ('dir /b *.mp3') do (
set "xand="
set /p "xand="
ren "%%~a" "%%~na!xand!%%~xa"
))


NOTE1: You can rename any type of files, not only mp3 as in the example, just replace mp3 with the type of files you want to rename (pdf, etc....)
NOTE2: DOS Scripts are case insensitive

User avatar
Cornflower
Posts: 244
Joined: Fri Aug 31, 2007 7:58 am
Location: Canada's capital

Re: File Renaming Using a List of Names

#2 Post by Cornflower »

Den4B's Renamer Lite can also do the same thing (https://www.portablefreeware.com/index.php?id=562)

The newer versions of Renamer Lite allows you to put that list (Alabama, Bershire, etc) either before or after the filename, whereas the last uninhibited version we have here only allows the list to be placed before the filename. I keep both versions and use the "Lite" version only on the rare occasion I need to use one of the extra features (like twice in 4 years) such as this so I don't save any rules.

I like the dos script, though. Cool!

User avatar
Cornflower
Posts: 244
Joined: Fri Aug 31, 2007 7:58 am
Location: Canada's capital

Re: File Renaming Using a List of Names

#3 Post by Cornflower »

@juverax. I found something! SubPad (https://www.portablefreeware.com/index.php?id=313)

Years ago, I used a text editor that had selection by columns. You would in your example append the names Alabama, Berkshire, ... to the bottom of your mp3 list and open the whole thing and then use Column selection mode to cut and paste your names to a column to the right of the mp3 list. I can't find that editor now (had other nifty things) but I notice Subpad does the same thing.

MP3.txt
Marching Band CD1_Part1.mp3
Marching Band CD1_Part2.mp3
Marching Band CD1_Part3.mp3
Marching Band CD1_Part4.mp3
Marching Band CD1_Part5.mp3

List.txt
Alabama
Berkshire
Carolina
Delaware
Esperanza

Make Batch file renfiles.bat with 5 lines containing ren
ren
ren
ren
ren
ren

From Dos
copy renfiles.bat+MP3.txt+list.txt

Open renfiles.bat in SubPad. Go into Options, Selection, and choose Column Mode

Now Select your MP3 files and move them to the right of "ren ", then move your list.txt files to the right of "ren ... .mp3 "

This description took me about 4 times as long as doing it in real time.

With the cool Dos Batch file you presented this may be a moot point, but I used to use the column cut and paste feature on occasion and for 429k, this is added to my toolkit (though not for Rename--Rename.exe works better and more intuitively for me.

Post Reply