Get files from subdirectories and copy

May 11, 2010 at 15:00:31
Specs: Windows 7
I have been trying to make a batch file that would search a directory and all its subdirectories for files with a specific extension and then copy thos files to a single new directory. I tried some wierd ideas using robocopy and for. Any ideas anybody?

See More: Get files from subdirectories and copy

Report •

May 11, 2010 at 15:11:47
use the /s on your dir.

dir Myfile.* /s

will search all sub directories for that file.

so your code would be

for /f %%a in ('dir myfile.* /s') do (

Report •

May 11, 2010 at 15:47:41
OK. I still can't get it. This is what I tried:

FOR /F %%A IN ('dir *.m4a /s') DO copy *.* MusicSet\

Can you get ideas from that?

Report •

May 11, 2010 at 18:47:04
I figured it out. Here's the code I used for those who care:

FOR /F "tokens=*" %%I IN ('dir Music\*.m4a /S /B') DO COPY /Y "%%I" MusicSet\

Report •

Related Solutions

May 13, 2010 at 06:39:20
I'm sure it works, but what happens if you do this:

XCOPY *.ext /S

The /S parameter will exclude empty directories, but it is to be seen if those empty directories are "directories without files" or "directories without files matching *.ext"

Report •

May 14, 2010 at 13:11:56
Actually, my purpose was to copy all of the .m4a files in all the directory and its sub-directories into one single directory so that I could see all the files at once instead of having to search through the directories for files and pick them out a couple at a time. I don't want any of the directories themselves copied.

Report •

December 22, 2010 at 23:16:44
What will be the dos command to copy all the *.txt files from my root/current drive to another destination?
i precisely mean to get all the *.txt files from all the directories and subdirectories.
plz reply

Report •

December 23, 2010 at 02:10:49

FOR /F "TOKENS=*" %%J IN ('DIR /B /S *.TXT') DO XCOPY /Y %%J D:\

Happy is ONE who says I am an OttoMAN.

Report •

Ask Question