Copy files with batch

January 1, 2009 at 15:09:43
Specs: Windows XP, a
Hello,
I am trying to write a script that copies all files in the directory tree to a folder without the folders. Only teh files inside them.
For example,
I have Folder1\Folder2\Folder3
and I want to copy all files in the 3 sub folders into Folder4.
I tried this but it fails:
For %%J in (*.*) Do (XCOPY "C:\Folder1\%%J" "C:\Folder2\" /Y)
Please Help

See More: Copy files with batch

Report •


#1
January 1, 2009 at 17:46:04

for /f "delims=" %%a in ('dir drive:\folder1\ /a-d /b /s') do copy "%%~fa" drive:\folder4\


Report •

#2
January 1, 2009 at 23:13:43
Thanks! That rocks!

Report •

#3
January 2, 2009 at 05:16:34
Another question,
Asuuming That I want to copy only files that Starts with 'Test'.
For example,
Copy only teh following files from all folders and sub-folders:
TestGen1.txt
TestGen56Big.csv...
Is it possible?

Report •

Related Solutions

#4
January 2, 2009 at 05:42:05
Yep, copy also supports wild cards.


for /f "delims=" %%a in ('echo "drive:\path\folder1"^&^&dir "drive:\path\folder1\" /ad /b /s') do >nul 2>&1 copy "%%~a\test*" "drive:\path\folder4"


Report •

#5
January 2, 2009 at 13:57:53
Thanks! You are great!
I will check and tell you my results in the next days!
Thanks again and come to visit ;-)

Report •


Ask Question