I have the following directory structure:
\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
In the event that a key file doesn't exist, I want to copy backup/* into the directory "test." This gets executed from 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
)
This gives me the following error and ends up just deleting everything in the "test" directory. I was able to copy everything from my test directory into the backup directory using robocopy
but I can't seem to get the opposite working.
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
switch is equivalent to /E /PURGE
/PURGE
instructs robocopy
to delete everything in the destination (test directory) that is not exist in your source (backup directory) before starting coping files, but since the backup directory itself is in the destination it will be deleted too.
Just replace /MIR
with /E
switch
User contributions licensed under CC BY-SA 3.0