Answers:
xcopy.exe
是这里的解决方案。它内置在Windows中。
xcopy /s c:\Folder1 d:\Folder2
xcopy
不推荐使用,当文件名超过254个字符时,会引发“内存不足”错误。使用robocopy
来代替:robocopy C:\Folder1 D:\Folder2 /COPYALL /E
en.wikipedia.org/wiki/Robocopy
如果您拥有robocopy,
robocopy C:\Folder1 D:\Folder2 /COPYALL /E
除此以外,
xcopy /e /v C:\Folder1 D:\Folder2
"C:\My Folder\"
你可能会得到一个讨厌的惊喜。我建议您仔细阅读SS64页面。有关“什么是CMD中的转义字符”兔子洞的完整介绍,请参见在批处理脚本中转义双引号。
我看到很多答案建议使用xcopy。但这是不必要的。正如该问题明确提到的那样,在这种情况下,作者希望文件夹中的内容而不是文件夹本身可以复制:
copy "C:\Folder1" *.* "D:\Folder2"
多数民众赞成在所有 xcopy
子目录都可以使用的情况下C:\Folder1
md D:\Folder2
copy
命令(Windows 10命令提示符)告诉我语法不正确。以下是正确的语法:copy "C:\Folder1\*.*" "D:\Folder2"
RoboCopy不适用于我,这里有一些好的解决方案,但是没有一个解释XCopy开关及其作用。另外,如果路径中有空格,则也需要使用引号。
xcopy / i / e“ C:\ temp \ folder 1”“ C:\ temp \ folder 2”
这是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)
@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
仅供参考...如果您使用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%
而且,就是这样!
添加到计划的任务中,永不回头。
@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
/S
复制目录和子目录(空目录除外),同时/E
复制目录和子目录(包括空目录)。/Q
在复制时不显示文件名,而在复制时/F
显示完整的源文件名和目标文件名。
我已经写了一个.bat文件,将文件复制并粘贴到一个临时文件夹中,并使其压缩并传输到smb挂载点,希望这会有所帮助,
@echo off
if not exist "C:\Temp Backup\" mkdir "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%"
if not exist "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP" mkdir "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP"
if not exist "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\Logs" mkdir "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\Logs"
xcopy /s/e/q "C:\Source" "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%"
Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\Logs"
"C:\Program Files (x86)\WinRAR\WinRAR.exe" a "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP\ZIP_Backup_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%.rar" "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\TELIUM"
"C:\Program Files (x86)\WinRAR\WinRAR.exe" a "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP\ZIP_Backup_Log_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%.rar" "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\Logs"
NET USE \\IP\IPC$ /u:IP\username password
ROBOCOPY "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP" "\\IP\Backup Folder" /z /MIR /unilog+:"C:\backup_log_%date:~-4,4%%date:~-10,2%%date:~-7,2%.log"
NET USE \\172.20.10.103\IPC$ /D
RMDIR /S /Q "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%"