ROBOCOPY更改输入路径名称,但不起作用

问题描述 投票:1回答:2

这是我的代码:

set thisfolder=%~dp0%
echo %thisfolder%

ROBOCOPY "%thisfolder%" "F:\batch testing\test\" copyself.bat

然而,问题出现在这里:

F:\batch testing>set thisfolder=F:\batch testing\

F:\batch testing>echo F:\batch testing\
F:\batch testing\

F:\batch testing>ROBOCOPY "F:\batch testing\" "F:\batch testing\test\" copyself.bat

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : Monday, March 5, 2018 7:26:54 AM
   Source : F:\batch testing" F:\batch\
     Dest : F:\batch testing\testing\test"\

    Files : copyself.bat

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

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

2018/03/05 07:26:54 ERROR 123 (0x0000007B) Accessing Source Directory F:\batch testing" F:\batch\
The filename, directory name, or volume label syntax is incorrect.

源路径和目标路径似乎失真。任何人都知道这是怎么回事?

windows batch-file robocopy
2个回答
1
投票

问题很简单。

ROBOCOPY "F:\batch testing\"

本来应该

ROBOCOPY "F:\batch testing"

Robocopy非常善变......


0
投票

鉴于您的运行脚本目录也是当前目录,我建议将%~dp0%(应该是%~dp0)更改为%CD%

另外,(正如您所注意到的),不需要在目录路径中添加尾部反斜杠。

事实上,如果你只是复制正在运行的脚本本身,那么我想它可能只包含:

@RoboCopy "%CD%" "%CD%\test" "%~nx0"

或者如果从其他位置运行它:

或者:

@Start "" /D"%~dp0" "Cmd /C RoboCopy . .\test "%~nx0""

要么:

@Start "" /D"%~dp0" "%__AppDir__%RoboCopy.exe" . .\test "%~nx0"
© www.soinside.com 2019 - 2024. All rights reserved.