Howto Mass Rename Based on Filelist as input

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Awal369
Posts: 3
Joined: 12 Feb 2013 05:16

Howto Mass Rename Based on Filelist as input

#1 Post by Awal369 » 12 Feb 2013 06:45

Hi everyone,

I receive a longlist file to be renamed in a text file with this format:

oldfilename;newfilename

for example
c:\Internal drawing\IN\100034.pdf;c:\Internal drawing\IN\DWG IN100034_a.pdf
c:\Internal drawing\IN\100045 c.pdf;c:\Internal drawing\IN\DWG IN100045_c.pdf
c:\Internal drawing\IN\100088.pdf;c:\Internal drawing\IN\DWG IN100088_d.pdf
....
c:\Internal drawing\HS\100465 b.pdf;c:\Internal drawing\IN\DWG HS100465_b.pdf
c:\Internal drawing\HS\100987.pdf;c:\Internal drawing\IN\DWG HS100987_a.pdf
...

No specific pattern, only old name and new name separated by semicolon in every line.

Need your help to make a batch file to solve it, that can also give a log file for reporting the name changes.


Thanks for your help.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Howto Mass Rename Based on Filelist as input

#2 Post by foxidrive » 12 Feb 2013 06:59

Try explaining what you want again - your example has ending letters in some names and yet they magically appear in all the new filenames.
The paths need to be confirmed too.

c:\Internal drawing\IN\100034.pdf;c:\Internal drawing\IN\DWG IN100034_a.pdf
c:\Internal drawing\IN\100045 c.pdf;c:\Internal drawing\IN\DWG IN100045_c.pdf
c:\Internal drawing\IN\100088.pdf;c:\Internal drawing\IN\DWG IN100088_d.pdf
....
c:\Internal drawing\HS\100465 b.pdf;c:\Internal drawing\IN\DWG HS100465_b.pdf
c:\Internal drawing\HS\100987.pdf;c:\Internal drawing\IN\DWG HS100987_a.pdf

Awal369
Posts: 3
Joined: 12 Feb 2013 05:16

Re: Howto Mass Rename Based on Filelist as input

#3 Post by Awal369 » 12 Feb 2013 07:32

The file is the result of drawing checking by engineer, ignore the ending letter ( I assume it is a revision).
I just want to rename files based on two information old name and new name.
And I need to get the history about this renaming process, maybe log file, like :
oldname1 renamed to newname1
oldname2 renamed to newname2
oldname3 renamed to newname3
.....

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Howto Mass Rename Based on Filelist as input

#4 Post by foxidrive » 12 Feb 2013 07:47

You mean that information is a file that you are given?

In that case try this with some test files: the input file is called file.txt
It assumes that the IN folder already exists.


Code: Select all

@echo off
for /f "tokens=1,2 delims=;" %%a in (file.txt) do (
ren "%%a" "%%~nxb"
move "%%~dpa\%%~nxb" "%%~dpb"
>>"file.log" echo "%%a" renamed and moved to "%%b"
)

Awal369
Posts: 3
Joined: 12 Feb 2013 05:16

Re: Howto Mass Rename Based on Filelist as input

#5 Post by Awal369 » 12 Feb 2013 21:25

Thank you very much.
It works. I prepare new folder with same subfolder tree and I modify your batch file to move the files.

Code: Select all

@echo off
for /f "tokens=1,2 delims=;" %%a in (tes.txt) do (
move "%%a" "%%b"
>>"file.log" echo "%%a" renamed and moved to "%%b"
)


Thanks for your help.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Howto Mass Rename Based on Filelist as input

#6 Post by foxidrive » 12 Feb 2013 22:09

Well, I have learned something. Move can rename a file in the same step.

Back in earlier days I don't think it could, so it was changed at some stage. Beauty!

Post Reply