Computing.Net > Forums > Programming > Copy images from sub directories

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Copy images from sub directories

Reply to Message Icon

Name: GanjaBlood
Date: January 25, 2008 at 04:08:43 Pacific
OS: XP
CPU/Ram: 3.2 P4/2048
Comment:

I would like to copy files from multiple sub directories to one folder so I used;

FOR /R "%1" %%G IN (*.JPG) DO COPY %%G C:\TEST\

However, if files of the same name exist they are overwritten.

How can I increment the filename or change the filename to something random as it isn't important?

I have tried multiple ways using the time as a random number generator but failed.

SET RANDOM=="%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%%TIME:~9,2%"

Please Help!



Sponsored Link
Ads by Google

Response Number 1
Name: GanjaBlood
Date: January 25, 2008 at 04:10:52 Pacific
Reply:

Oops, forget to mention this is a batch file under NT. Cheers!


0

Response Number 2
Name: Mechanix2Go
Date: January 25, 2008 at 04:23:07 Pacific
Reply:

First, NT has a %random% built in.

For this purpose, incrementing wil work OK.

::== incNAME
@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir/s/b/a-d \files\*.txt') do (
set /a N+=1
echo ren "%%a" "!N!%%~Na.txt"
)



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 3
Name: Mechanix2Go
Date: January 25, 2008 at 04:27:53 Pacific
Reply:

well... almost

::==
@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir/s/b/a-d \files\*.txt') do (
set /a N+=1
echo copy "%%a" "c:\test\!N!%%~Na.txt"
)



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 4
Name: GanjaBlood
Date: January 25, 2008 at 07:17:54 Pacific
Reply:

I can't seem to get this to work..

It's performing the command on each file but I don't understand your method of incrementation to fix this?

set /a N+=1 echo copy "U:\Visio Drawings\cisco6509.JPG" "c:\test\!N!cisco6509.jpg"
Missing operator.


0

Response Number 5
Name: Mechanix2Go
Date: January 25, 2008 at 08:20:07 Pacific
Reply:

this:

set /a N+=1 echo copy "U:\Visio Drawings\cisco6509.JPG" "c:\test\!N!cisco6509.jpg"

needs to be TWO lines within the FOR.

As iis, it doesn't DO the copy, it just previews it. To activate it, remove the ECHO.


set /a N+=1
copy "U:\Visio Drawings\cisco6509.JPG" "c:\test\!N!cisco6509.jpg"


=====================================
If at first you don't succeed, you're about average.

M2



0

Related Posts

See More



Response Number 6
Name: klint
Date: January 25, 2008 at 09:27:49 Pacific
Reply:

The original line was:

echo copy "%%a" "c:\test\!N!%%~Na.txt"

The fact that it expanded the %%a but not the !N! means that you did not put this line in your file:

setLocal EnableDelayedExpansion

Did you think that line was not important?


0

Response Number 7
Name: GanjaBlood
Date: January 28, 2008 at 02:29:57 Pacific
Reply:

Thanks for all your help M2 it's working perfectly now!

setLocal EnableDelayedExpansion was in my file, it was simply a case of not being on two lines within the FOR as noted by M2.

Thanks again!


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Copy images from sub directories

Copy from multiple directories www.computing.net/answers/programming/copy-from-multiple-directories/16232.html

Copy files from mult. subfolders www.computing.net/answers/programming/copy-files-from-mult-subfolders/13105.html

batch file copy without overwrite www.computing.net/answers/programming/batch-file-copy-without-overwrite/12885.html