This is the code I have:
set thisfolder=%~dp0%
echo %thisfolder%
ROBOCOPY "%thisfolder%" "F:\batch testing\test\" copyself.bat
However the issue presents itself here:
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.
The source and destination paths seem distorted. Anyone know what's up with that?
The issue was simple.
ROBOCOPY "F:\batch testing\"
should have been
ROBOCOPY "F:\batch testing"
Robocopy is extremely fickle...
Given that your running script directory is also the current directory, I'd suggest changing %~dp0%
, (which should really have been %~dp0
), to %CD%
.
Also, (as you've noticed), there should be no need to add a trailing backslash to your directory paths.
In fact if you're only copying the running script itself, then I suppose it could just contain:
@RoboCopy "%CD%" "%CD%\test" "%~nx0"
Or if running it from another location:
Either:
@Start "" /D"%~dp0" "Cmd /C RoboCopy . .\test "%~nx0""
Or:
@Start "" /D"%~dp0" "%__AppDir__%RoboCopy.exe" . .\test "%~nx0"
User contributions licensed under CC BY-SA 3.0