如何使用Windows批次復制文件?

[英]How do I copy files using Windows Batch?


I have a directory with several subdirectories with files.
How can I copy all files in the subdirectories to a new location?

我有一個目錄,有幾個子目錄和文件。如何將子目錄中的所有文件復制到新位置?

Edit: I do not want to copy the directories, just the files...

編輯:我不想復制目錄,只是文件…

As this is still on XP, I chose the below solution:

由於這仍然是XP,我選擇了以下解決方案:

 for /D %S IN ("src\*.*") DO  @COPY "%S\" "dest\"

Thanks!

謝謝!

6 个解决方案

#1


6  

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
)

#2


3  

The Xcopy command should help here.

Xcopy命令在這里應該有所幫助。

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:

或者如果您不想要SrcDir中的任何文件,只是子目錄,您可以結合FOR命令使用XCOPY:

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

#3


2  

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

robocopy“c:\源”“c:\目的地”/ E

#4


1  

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

在批處理文件與命令行中,將%f更改為%f

#5


0  

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

如果你想在另一端保持相同的文件夾結構,聽起來就像XCOPY一樣簡單

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

選擇復制文件c:\ \ *。* d:\ \ / s

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

如果您想要復制空目錄,請使用/e而不是/s。

#6


0  

 for /D %S IN ("src\*.*") DO  @COPY "%S\" "dest\"

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2008/10/09/7075f3358ca16c0ee9e15fa6368e89af.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com