Page 1 of 1

Copying all Files within directories to one directory

Posted: 10 Sep 2009 10:30
by dubhubb
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?

Posted: 10 Sep 2009 13:55
by avery_larry
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"

Posted: 14 Sep 2009 08:55
by dubhubb
Thank you! I got it work with the syntax you suggested! :D