windows 使用批处理文件将文件夹的所有内容复制到另一个文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4601161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
copying all contents of folder to another folder using batch file?
提问by SCM
I have a folder in C:\Folder1
我有一个文件夹 C:\Folder1
I want to copy all the contents of Folder1
to another location, D:\Folder2
我想将 的所有内容复制Folder1
到另一个位置,D:\Folder2
How do I do this using a batch file?
如何使用批处理文件执行此操作?
回答by eHussain
xcopy.exe
is the solution here. It's built into Windows.
xcopy.exe
是这里的解决方案。它内置于 Windows 中。
xcopy /s c:\Folder1 d:\Folder2
You can find more options at http://www.computerhope.com/xcopyhlp.htm
您可以在http://www.computerhope.com/xcopyhlp.htm找到更多选项
回答by mghicks
If you have robocopy,
如果你有机器人,
robocopy C:\Folder1 D:\Folder2 /COPYALL /E
otherwise,
除此以外,
xcopy /e /v C:\Folder1 D:\Folder2
回答by ghiboz
if you want remove the message that tells if the destination is a file or folder you just add a slash:
如果你想删除告诉你目的地是文件还是文件夹的消息,你只需添加一个斜杠:
xcopy /s c:\Folder1 d:\Folder2\
xcopy /s c:\Folder1 d:\Folder2\
回答by Kingzel
I see a lot of answers suggesting the use of xcopy. But this is unnecessary. As the question clearly mentions that the author wants THE CONTENT IN THE FOLDER not the folder itself to be copied in this case we can -:
我看到很多建议使用 xcopy 的答案。但这是不必要的。由于问题清楚地提到作者希望在这种情况下复制文件夹中的内容而不是文件夹本身,我们可以-:
copy "C:\Folder1" *.* "D:\Folder2"
Thats allxcopy
can be used for if any subdirectory exists in C:\Folder1
这就是所有xcopy
可用于如果存在任何子目录C:\Folder1
回答by Jordan
RoboCopy did not work for me, and there are some good solutions here, but none explained the XCopy switches and what they do. Also you need quotes in case your path has spaces in it.
RoboCopy 对我不起作用,这里有一些很好的解决方案,但没有人解释 XCopy 开关及其功能。如果您的路径中有空格,您还需要引号。
xcopy /i /e "C:\temp\folder 1" "C:\temp\folder 2"
xcopy /i /e "C:\temp\folder 1" "C:\temp\folder 2"
Here is the documentation from Microsoft:
以下是微软的文档:
/s: Specifies to include subdirectories. Excludes empty subdirectories
/e: Copies all subdirectories, even if they are empty
/i: specifies the destination is a folder (Otherwise it prompts you)
回答by hampusma
@echo off
xcopy /s C:\yourfile C:\anotherfile\
This is how it is done! Simple, right?
这就是它的做法!很简单吧?
回答by DirtyDog
On my PC, xcopy and robocopy need also the path to them, i.e. C:\Windows\System32\xcopy.exe
在我的 PC 上,xcopy 和 robocopy 也需要它们的路径,即 C:\Windows\System32\xcopy.exe
That's why I use simply "copy": copy /y ....\Folder1\File.txt ....\Folder2\
这就是为什么我只使用“复制”:复制 /y ....\Folder1\File.txt ....\Folder2\
回答by Akash Dahiwelkar
@echo off
::Ask
echo Your Source Path:
set INPUT1=
set /P INPUT1=Type input: %=%
echo Your Destination Path:
set INPUT2=
set /P INPUT2=Type input: %=%
xcopy %INPUT1% %INPUT2% /y /s
回答by TheKirkwoods
FYI...if you use TortoiseSVN and you want to create a simple batch file to xcopy (or directory mirror) entire repositories into a "safe" location on a periodic basis, then this is the specific code that you might want to use. It copies over the hidden directories/files, maintains read-only attributes, and all subdirectories and best of all, doesn't prompt for input. Just make sure that you assign folder1 (safe repo) and folder2 (usable repo) correctly.
仅供参考...如果您使用 TortoiseSVN 并且您想创建一个简单的批处理文件以定期将整个存储库 xcopy(或目录镜像)到“安全”位置,那么这就是您可能想要使用的特定代码。它复制隐藏的目录/文件,维护只读属性和所有子目录,最重要的是,不提示输入。只需确保您正确分配了 folder1(安全存储库)和 folder2(可用存储库)。
@echo off
echo "Setting variables..."
set folder1="Z:\Path\To\Backup\Repo\Directory"
set folder2="\Path\To\Usable\Repo\Directory"
echo "Removing sandbox version..."
IF EXIST %folder1% (
rmdir %folder1% /s /q
)
echo "Copying official repository into backup location..."
xcopy /e /i /v /h /k %folder2% %folder1%
And, that's it folks!
而且,就是这样的人!
Add to your scheduled tasks and never look back.
添加到您的计划任务中,永不回头。
回答by Vaibhav Veralkar
@echo off
:: variables
echo Backing up file
set /P source=Enter source folder:
set /P destination=Enter Destination folder:
set xcopy=xcopy /S/E/V/Q/F/H/I/N
%xcopy% %source% %destination%
echo files will be copy press enter to proceed
pause