Copy and Rename files with sequential number

September 9, 2009 at 09:41:17
Specs: Windows XP
Can anyone help me with batch file code for the following scenario?

I need to copy *.JPG files from 4 removable drives F:\ , G:\ , H:\ and I:\ to a single backup directory Y:\images

The directory structure of each drive is F:\DCIM\100_FUJI\*.JPG - but the 100_FUJI could change, so I need to look for all *.JPG's within any folder structure on F:\ to I:\

I would also like to rename the .JPG's
F:\*.JPG would rename to S1-####.JPG
G:\*.JPG would rename to S2-####.JPG
H:\*.JPG would rename to S3-####.JPG
I:\*.JPG would rename to S4-####.JPG

#### being a sequential number

Any assistance or direction is much appreciated.


See More: Copy and Rename files with sequential number

Report •


#1
September 9, 2009 at 10:38:01
@echo off & setLocal EnableDELAYedExpansion

set N=
for %%s in (f g h i) do (
if %%s equ f set pre=S1
if %%s equ g set pre=S2
if %%s equ h set pre=S3
if %%s equ i set pre=S4

for /f "tokens=* delims= " %%a in ('dir/s/b/a-d %%s:\*.jpg') do (
set /a N+=1
copy %%a d:\!pre!-!N!.jpg
)
)


=====================================
Helping others achieve escape felicity

M2


Report •

#2
September 9, 2009 at 11:35:57
Wow - That was fast - Thank you

Unfortunately I get:

The system cannot find the path specified
0 files copied

repeated


Report •

#3
September 9, 2009 at 12:01:07
So, are there jpgs on those frives?

I got this:

copy i:\test.jpg d:\S4-1.jpg
copy i:\tested.jpg d:\S4-2.jpg


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
September 9, 2009 at 12:10:42
Yes but in a directory structure:

F:\DCIM\100_FUJI\DSCF0001.JPG
F:\DCIM\100_FUJI\DSCF0002.JPG
F:\DCIM\100_FUJI\DSCF0003.JPG
F:\DCIM\100_FUJI\DSCF0004.JPG
etc
Same for G:\, H:\ and I:\


Report •

#5
September 9, 2009 at 12:59:06
I don't know what your problem is.

=========================
C:\temp\->dir/b/s i:\*.jpg
i:\test.jpg
i:\tested.jpg
i:\DCIM\100_FUJI\new.jpg
i:\DCIM\100_FUJI\newer.jpg

C:\temp\->dir/b/s d:\*.jpg
d:\S4-1.jpg
d:\S4-2.jpg
d:\S4-3.jpg
d:\S4-4.jpg


=====================================
Helping others achieve escape felicity

M2


Report •

#6
September 9, 2009 at 13:42:16
Anything to do with operating system?

Running XP service pack 3

Saving to Y:\ which is a mapped network drive?


Report •

#7
September 9, 2009 at 15:15:03
This Works:

@echo off & setLocal EnableDELAYedExpansion

set N=
for %%s in (f g h i) do (
if %%s equ f set pre=S1
if %%s equ g set pre=S2
if %%s equ h set pre=S3
if %%s equ i set pre=S4

for /f "tokens=* delims= " %%a in ('dir/s/b/a-d %%s:\*.jpg') do (
set /a N+=1
copy %%a Y:\!pre!-!N!.jpg
)
)

However I need to specify a sub folder on Y:\ and if i change to Y:\images\folder\!pre!-!N!.jpg
it does not work


Report •

#8
September 9, 2009 at 15:50:43
The directory needs to exist for it to work.

How do I get it to create the folders if they do not exist?


Report •

#9
September 9, 2009 at 21:39:18
md y:\dirname\subname


and so on


=====================================
Helping others achieve escape felicity

M2


Report •

#10
September 10, 2009 at 15:12:51
Many Thanks Mechanix2Go

Report •


Ask Question