Changing Directory Names

  • Thread starter Thread starter Conrad Allen
  • Start date Start date
C

Conrad Allen

I get my pictures back from the film processor (yeah, I still use film)
along with
a CD containing a copy of each image and a thumbnail of each, too.
The images are named like
021434-R1-024-5A.jpg
021434-R1-032-12A.jpg
I want to change all the files thusly with one command:

For those numbered below 10A I want to add a leading 0 before its number
021434-R1-024-05A.jpg
And for all of them, I want to eliminate the unknown number in the middle
of the file name. I.E. the -024, or the -032 in my examples. So the final
filename looks like the following:
021434-R1-05A.jpg
021434-R1-12A.jpg
Got any ideas how to do this?? Seems when I do the wildcard deal from a
command line, I'm all messed up because the length of the filename cannot
be changed.
 
Conrad Allen said:
I get my pictures back from the film processor (yeah, I still use film)
along with
a CD containing a copy of each image and a thumbnail of each, too.
The images are named like
021434-R1-024-5A.jpg
021434-R1-032-12A.jpg
I want to change all the files thusly with one command:

For those numbered below 10A I want to add a leading 0 before its number
021434-R1-024-05A.jpg
And for all of them, I want to eliminate the unknown number in the middle
of the file name. I.E. the -024, or the -032 in my examples. So the final
filename looks like the following:
021434-R1-05A.jpg
021434-R1-12A.jpg
Got any ideas how to do this?? Seems when I do the wildcard deal from a
command line, I'm all messed up because the length of the filename cannot
be changed.

Try this batch file:

line1 @echo off
line2 dir /b *.jpg > c:\temp.txt
line3 for /F "tokens=1-5 delims=-." %%a in (c:\temp.txt) do call :Sub %%a
%%b %%c %%d %%e
line4 del c:\temp.txt
line5 goto :eof
line6
line7 :Sub
line8 set index=%4
line9 if "%index:~2,1%"=="" set index=0%index%
line10 echo ren %1-%2-%3-%4.%5 %1-%2-%index%.%5

Remove the "echo" command in Line 10 to activate the batch file.
 
This will do 0-9 (16 x ? for 0-9 and 17 for 10+)

For %%A in (????????????????.jpg) do (
FOR /F "usebackq tokens=1,2,3,4,5* delims=-" %%L in ('%%A') do (
Copy "%%A" "%%L-%%M-0%%O"

)
)

And this 10+ (note removal of 0 from last line)
For %%A in (?????????????????.jpg) do (
FOR /F "usebackq tokens=1,2,3,4,5* delims=-" %%L in ('%%A') do (
Copy "%%A" "%%L-%%M-%%O"

)
)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top