我正在使用 robocopy 将文件夹和文件从源复制到目标。
来源路径:
folder1
folder2
folder3
file1.txt
file2.log
file3.png
目标路径:
folder_important
folder1
folder2
这是我的命令
set exclude_ext_from_copy=*.log *.txt*
set exclude_folder_from_copy=folder3
robocopy "origin_path" "dest_path" /E /COPYALL /PURGE /MIR /IS /IT /TEE /FFT /ETA /R:10 /W:5 /ZB /V /XF %exclude_ext_from_copy% /XD %exclude_folder_from_copy% /LOG:"%HOMEPATH%\Desktop\log.txt"
在目标路径上:
folder1
folder2
file3.png
您可以看到它从复制中排除了“folder3”以及扩展名为“* .log”和“* .txt”的文件。到目前为止一切顺利。
现在我想防止 robocopy 删除“dest_path”上的文件夹“folder_important”。我该如何排除它(或保护它不被删除)。谢谢
失败的尝试:
attrib +s +h dest_path\folder_important
robocopy etc etc
attrib -s -h dest_path\folder_important
答案1
一个非常简单的例子,在将命令结构应用于重要文件之前,测试您是否使用了正确的命令结构
测试程序:
CD %~dp0
Tree /F /A
Robocopy source dest /Purge /Mir /XD leave retain
Tree /F /A
Exit /B
输出:
C:\Users\tcdou\Desktop\rcT>CD C:\Users\tcdou\Desktop\rcT\
C:\Users\tcdou\Desktop\rcT>Tree /F /A
Folder PATH listing for volume Windows
Volume serial number is E05B-0DE4
C:.
| demo.log
| RCexample.bat
|
+---dest
| | one.txt
| |
| +---Remove
| \---retain
\---source
| one.txt
|
\---leave
C:\Users\tcdou\Desktop\rcT>Robocopy source dest /Purge /Mir /XD leave retain
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Saturday, 16 May 2020 10:17:02 PM
Source : C:\Users\tcdou\Desktop\rcT\source\
Dest : C:\Users\tcdou\Desktop\rcT\dest\
Files : *.*
Exc Dirs : leave
retain
Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /R:1000000 /W:30
------------------------------------------------------------------------------
1 C:\Users\tcdou\Desktop\rcT\source\
*EXTRA Dir -1 C:\Users\tcdou\Desktop\rcT\dest\Remove\
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 2 0 2 0 0 2
Files : 1 0 1 0 0 0
Bytes : 0 0 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : Saturday, 16 May 2020 10:17:02 PM
C:\Users\tcdou\Desktop\rcT>Tree /F /A
Folder PATH listing for volume Windows
Volume serial number is E05B-0DE4
C:.
| demo.log
| RCexample.bat
|
+---dest
| | one.txt
| |
| \---retain
\---source
| one.txt
|
\---leave
C:\Users\tcdou\Desktop\rcT>Exit /B
从这个简单的测试中可以明显了解到,您可以使用/XD 开关指定多个文件夹,以从源文件夹和目标文件夹中的操作中排除。