switch xcopy to robocopy

0

I am using the following script. When I swap out the "move" with "robocopy /mov /mt" it doesn't work. The destination goes one level too deep and takes the name of the file as the destination folder. Error is below too.

How can I use robocopy instead? I need the multithreading.

Error= ERROR 123 (0x0000007B) Accessing Source Directory D:\source\FILE.tif\ The filename, directory name, or volume label syntax is incorrect.

@echo off

SETLOCAL ENABLEDELAYEDEXPANSION

SET Source=D:\source
SET Destination=D:\dest

Echo Gather Top 30 files
set SrcCount=0
set SrcMax=31
FOR /F "TOKENS=*" %%a IN ('dir /A-D /O-D /B "%Source%"\*.*') DO (
    SET /A SrcCount += 1
    if !SrcCount! LEQ %SrcMax% (
MOVE "%source%\%%a" "%destination%
  )
)

This is what I am trying:

@echo off

SETLOCAL ENABLEDELAYEDEXPANSION

SET Source=D:\source
SET Destination=D:\dest

Echo Gather Top 30 files
set SrcCount=0
set SrcMax=31
FOR /F "TOKENS=*" %%a IN ('dir /A-D /O-D /B "%Source%"\*.*') DO (
    SET /A SrcCount += 1
    if !SrcCount! LEQ %SrcMax% (
robocopy /mov /mt "%source%\%%a" "%destination%
  )
)
batch-file
robocopy
asked on Stack Overflow Jun 1, 2016 by Tom Wildt • edited Jun 1, 2016 by Tom Wildt

1 Answer

1

Look at the arguments to robocopy:

robocopy /?

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

  Started : Wed Jun 01 18:46:40 2016

              Usage :: ROBOCOPY source destination [file [file]...] [options]

             source :: Source Directory (drive:\path or \\server\share\path).
        destination :: Destination Dir  (drive:\path or \\server\share\path).
               file :: File(s) to copy  (names/wildcards: default is "*.*").

The first argument is a Source Directory, not a file. You are passing a file name.

So, do this instead:

robocopy /mov /mt "%source%" "%destination%" "%%a"

As for the /MT option, I think the threads are used to copy different files, not different parts of the same file.

Since you only call it with one file at a time, I don't believe you'll actually get any multi-threaded copying.

You'll need to gather all 30 file names in a single string so the result after substitution will be a single execution of robocopy like this:

robocopy /mov /mt "sourceDir" "destDir" "file1" "file2" "file3" ... "file30"
answered on Stack Overflow Jun 1, 2016 by Andreas • edited Jun 20, 2020 by Community

User contributions licensed under CC BY-SA 3.0