How do I copy files using Windows Batch?

∥☆過路亽.° 提交于 2019-12-05 17:47:03

Ok. With your edit that says you don't want the directory structure, i think you're going to want to use something like this:

for /F "usebackq" %s IN (`DIR /B /S /A-D SrcDir`) DO @(
    XCOPY %s DestDir\%~nxs
)

The Xcopy command should help here.

XCOPY /E SrcDir\*.* DestDir\

Or if you don't want any of the files in SrcDir, just the sub directories, you can use XCOPY in conjunction with the FOR command:

FOR /D %s IN (SrcDir\*) DO @XCOPY /E %s DestDir\%~ns\

robocopy "c:\source" "c:\destination" /E

If I understood you correctly you have a big directory tree and you want all the files inside it to be in one directory. If that's correct, then I can do it in two lines:

dir /s /b "yourSourceDirectoryTreeHere" > filelist.txt
for /f %f in (filelist.txt) do @copy %f "yourDestinationDirHere"

In a batch file vs. the command line change %f to %%f

If you want to keep the same folder structure on the other end, sounds as simple as XCOPY

xcopy c:\old\*.* d:\new\ /s

Use /e instead of /s if you want empty directories copied too.

 for /D %S IN ("src\*.*") DO  @COPY "%S\" "dest\"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!