Robocopy with environment variable will cause 0x10

environment-variablesrobocopytask-scheduler

I tried this on command line and it will work correctly

robocopy /mir /copy:DAT /mot:30  "D:\Source File\file" "E:\Target Directory\backup %DATE:/=-% %time::=-%" /xd "D:\Source File\file\excluded"

But after I create a schedule task to run it, I got 0x10 result

It will just run correctly if I remove this part

%DATE:/=-% %time::=-%

Any suggestion, will help me a lot.

thanks

Best Answer

I don't think robocopy would understand how to translate the variable %DATE:/=-% or %time::=-% natively. Try changing your scheduled task to run cmd and call robocopy from there.

cmd /c robocopy /mir /copy:DAT /mot:30  "D:\Source File\file" "E:\Target Directory\backup %DATE:/=-% %time::=-%" /xd "D:\Source File\file\excluded"