PnP
PnP

Reputation: 3185

Custom file copy with Robocopy

Where the text file contains a list of files, as below code, but it errors saying the %%a is an invalid parameter even though it correctly sees %%a as the file name.

Any way around this?

EDIT:

for /f "delims=" %%a in (C:\audit\test.txt) do (
  robocopy "%%~dpa" "Z:" "%%~nxa" /S /E /COPY:DAT /PURGE /MIR /R:1000000 /W:30
)
pause

Upvotes: 1

Views: 363

Answers (1)

Andriy M
Andriy M

Reputation: 77707

A file name argument of ROBOCOPY cannot include the path, whether absolute or relative. It should be just a name (with the extension). (Alternatively it can be a mask.)

If your text file contains full paths, you can extract names and extensions only using the ~nx combined modifier:

for /f "delims=" %%a in (C:\audit\test.txt) do (
  robocopy "C:\Test1" "C:\Test2" "%%~nxa" /S /E /COPY:DAT /PURGE /MIR /R:1000000 /W:30
)

Also, consider enclosing all your path/file names in double quotes, as you can see above, to avoid having issues with names containing spaces and/or special characters.

Upvotes: 1

Related Questions