Copying all Files within directories to one directory

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dubhubb
Posts: 7
Joined: 04 Sep 2009 09:55

Copying all Files within directories to one directory

#1 Post by dubhubb » 10 Sep 2009 10:30

I need to be able to copy only the files out of several directories and place them into one directory.

I have one directory and within that directory I have about 5 other directories. Within each of those 5 directories there are about 50 or so .tiff files.

I need to copy only the .tiff files into a single directory.

Right now I have the following command:

FOR /f %%I IN ("%userprofile%\desktop\output\*.tif") DO xcopy /s "%%I" "%userprofile%\desktop\hf"

This moves the .tiff files but it also moves the 5 directories as well, and I need it just to move the .tiff files and just lump them into one directory.

Any Ideas?

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 10 Sep 2009 13:55

Your for loop is quite superfluous. All you're actually doing is this:

Code: Select all

xcopy /s "%userprofile%\desktop\output\*.tif" "%userprofile%\desktop\hf"


A variation on this should work for you:

Code: Select all

for /R "%userprofile%\desktop\output" %%a in (*.tif) do copy "%%~a" "%userprofile%\desktop\hf"


Or perhaps:

Code: Select all

for /f %%a in ('dir /b /s /a-d "%userprofile%\desktop\output\*.tif"') do copy "%%~a" "%userprofile%\desktop\hf"

dubhubb
Posts: 7
Joined: 04 Sep 2009 09:55

#3 Post by dubhubb » 14 Sep 2009 08:55

Thank you! I got it work with the syntax you suggested! :D

Post Reply