Robocopy showing invalid parameter

こ雲淡風輕ζ 提交于 2019-12-12 01:48:50

问题


I am making a backup programme for my institute but robocopy copy showing

  Started : 11 April 2015 01:21:07 PM
   Source - F:\Training\HPES\CoreJava\
     Dest - F:\11-04-2015\

    Files :
  Options : /DCOPY:DA /COPY:DAT /R:1000000 /W:30

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

ERROR : Invalid Parameter #3 : "\0121PM"

       Simple Usage :: ROBOCOPY source destination /MIR

             source :: Source Directory (drive:\path or \\server\share\path).
        destination :: Destination Dir  (drive:\path or \\server\share\path).
               /MIR :: Mirror a complete directory tree.

    For more usage information run ROBOCOPY /?

My code

for /f "tokens=1* delims=" %%a in ('date /T') do set datestr=%%a

for /f "tokens=1,2,3 delims=: " %%A in ('TIME /T') do set mytime=%%A%%B%%C
pause
mkdir %datestr%
cd %datestr%
mkdir %mytime%
cd %mytime%

pause
robocopy F:\Training\HPES\CoreJava F:\%datestr%\%mytime%  /e
pause

It is showing invalid parameter error but when i run this code by removing %mytime% block in source part then it works all good. HELP


回答1:


In

for /f "tokens=1* delims=" %%a in ('date /T') do set datestr=%%a

the date /t includes an space at the end of its output, and this space is included in the datestr variable and in the final command you execute using the variable. So F:\%datestr%\%mytime% includes an space (at the end of %datestr%, converting one argument into two.

If you want to keep the space, then use quotes: "F:\%datestr%\%mytime%"

If you don't want to keep the space, seeing your output you can change to

for /f %%a in ("%date%") do set "datestr=%%a"


来源:https://stackoverflow.com/questions/29575512/robocopy-showing-invalid-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!