sn0
asked on
Scripting "fx." to file name?
I have a client who, for his website, needs a group of images (15,000+) renamed with a "fx." prefix. So, something similar to going from 001002.jpg to fx.001002.jpg.
My goal is to write a command script or find a way to automate this but I'm not having any luck with the copy or xcopy commands.
My goal is to write a command script or find a way to automate this but I'm not having any luck with the copy or xcopy commands.
As a batch file, it is looking much smaller:
@echo off
rem if you want to be prompted for the folder, remove REM
REM set /P target=Which folder to use?
rem if you want to setup a fixed folder,remove REM
set target=c:\test
for %%F in ("%target%\*.jpg") do ren %%F "fx.%%~nxF"
If you didn't want the . you could do it with an _ or - say with just one line:
rename *.* fx_*.*
If it were me I'd probably use a for loop anyway mind.
Steve
rename *.* fx_*.*
If it were me I'd probably use a for loop anyway mind.
Steve
The ren with wildcards is buggy, and hence unreliable. I only use it if I want to replace parts, or insert parts between dots. Anything else is producing unexpected results in most cases. That is why I used a FOR loop, which gives you much more control over what is done.
Agreed there qlemo.. it works when it does and sometimes not quite the expected way - I.e you can't rename to inc fx. at the start etc.
Steve
Steve
ASKER
Qlemo: Your batch file works great except it renames the first file, for example: blah.jpg, to fx.fx.blah.jpg.
Not a big deal since it's only one file that it does it to (the first one) but, is there a way to get it to stop at the end of the group rather than going back to the beginning and stopping?
Not a big deal since it's only one file that it does it to (the first one) but, is there a way to get it to stop at the end of the group rather than going back to the beginning and stopping?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Qlemo: I had to edit line 10 because "ren" appeared twice and was prohibiting the code from doing anything but, aside from that, it works perfectly.
Thank you very much.
@echo off
setlocal EnableDelayedExpansion
rem if you want to be prompted for the folder, remove REM
REM set /P target=Which folder to use?
rem if you want to setup a fixed folder,remove REM
set target=c:\test
for %%F in ("%target%\*.jpg") do (
set x=%%~nF
if not "!x:~,3!" == "fx." ren %%F "fx.%%~nxF"
)
ASKER
"ren" appears twice in line 10 which prevents the code from working correctly. Remove the 2nd instance of "ren" and it works perfectly.
Open in new window