批处理robocopy正在删除我的所有文件

时间:2018-07-15 08:05:35

标签: batch-file robocopy

我具有以下目录结构:

\Users\DorrisPringle\Desktop\test
\Users\DorrisPringle\Desktop\test\mycopy.bat
\Users\DorrisPringle\Desktop\test\backup
\Users\DorrisPringle\Desktop\test\backup\asdf.txt
\Users\DorrisPringle\Desktop\test\backup\a_directory
\Users\DorrisPringle\Desktop\test\backup\a_directory\qwer.txt

如果密钥文件不存在,我想将backup / *复制到目录“ test”中。这是从mycopy.bat执行的:

if exist "\Users\DorrisPringle\Desktop\test\myservice.exe" (
    echo "all is good."
) else (
    robocopy "\Users\DorrisPringle\Desktop\test\backup" "\Users\DorrisPringle\Desktop\test" /MIR /R:1 /W:2
)

这给了我以下错误,最终只是删除了“ test”目录中的所有内容。我可以使用robocopy将测试目录中的所有内容复制到备份目录中,但是似乎无法正常工作。

  Started : Sunday, July 15, 2018 3:59:19 AM
   Source : C:\Users\DorrisPringle\Desktop\test\backup\
     Dest : C:\Users\DorrisPringle\Desktop\test\

    Files : *.*

  Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /R:1 /W:2

------------------------------------------------------------------------------

                           1    C:\Users\DorrisPringle\Desktop\test\backup\
        *EXTRA Dir        -1    C:\Users\DorrisPringle\Desktop\test\backup\
          *EXTRA File                  0        asdf.txt
        *EXTRA Dir        -1    C:\Users\DorrisPringle\Desktop\test\backup\a_directory\
          *EXTRA File                  0        qwer.txt
          *EXTRA File                177        s.bat
            New File                   0        asdf.txt
2018/07/15 03:59:19 ERROR 3 (0x00000003) Copying File C:\Users\DorrisPringle\Desktop\test\backup\asdf.txt
The system cannot find the path specified.

1 个答案:

答案 0 :(得分:1)

/MIR开关等效于/E /PURGE

/PURGE指示robocopy删除目标(测试目录)中源文件(备份目录)中不存在的所有内容,然后再开始处理文件,但是由于备份目录本身位于目标文件中它也会被删除。

只需将/MIR替换为/E开关