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

batch robocopy is deleting all of my files

我有以下目录结构:

\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.

/MIR开关相当于/E /PURGE

/PURGE 指示 robocopy 在开始复制文件之前删除源(备份目录)中不存在的目标(测试目录)中的所有内容,但由于备份目录本身位于目的地也将被删除。

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