Batch rename with a twist

Microsoft Windows 7 professional - upgra...
January 13, 2010 at 07:09:51
Specs: Windows 7
I have a folder with thousands of image files named with a number that is associated with members of my organization. Every couple of days, a few hundred members have their numbers change. I am able to aquire the old number and the new numbers in a csv file. It will have the old number (comma) new number per line. What I am trying to do is read the csv file, and rename the image files IF the old number does exist and IF the new number does not exist.

Any help would be fantastic


See More: Batch rename with a twist

Report •


#1
January 13, 2010 at 14:05:32
this gives you a log file in case of problems...
@echo off>rname.bat & setlocal enabledelayedexpansion
for /f "tokens=1-2 delims=," %%a in (list) do (
if exist %%a (
if not exist %%b (
echo ren %%a %%b>>rbname.bat
) else (
echo ::attempted duplicate: %%b already there>>rname.bat
)
) else (
echo ::no identity exists: %%a>>rname.bat
)
)
::allow view of results, safety is ON
more rname.bat
::rname.bat

Report •

#2
January 14, 2010 at 05:40:04
So far so good. Things are looking right. I have one more problem though, I need to add .jpg to the %%a and %%b variables. How do I do that within the "for" loop?

Edit: Also, when I remove the extensions from a picture file just to test, the rbname.bat file says that the rename was successfull, yet the file doesn't get renamed.

Edit Edit: OK, so I was able to get it to actually rename by adding another line of code. It now looks like this:

ren %%a %%b
echo ren %%a %%b>>rbname.txt


Report •

#3
January 14, 2010 at 06:36:58
did you take the safety off here? (remove the colons from
the line ::rname.bat)
::allow view of results, safety is ON
more rname.bat
:: safety is ON (no rename) until colons removed foll line.
::rname.bat

(but if its working now, just leave it at that.)
also, to get .jpg extension, just add it to all the var.s wherever they occur, like %%a make it %%a.jpg and %%b -> %%b.jpg


Report •

Related Solutions

#4
January 14, 2010 at 07:01:43
You sir are a God amongst men. That certainly did the trick. Funny how easy it was, I was trying all these concantonation techniques to get it to work.

Also, I didn't knwo what you meant by "safety" so I didn't even notice that part. But ya, it definitely works.


Report •


Ask Question