We help IT Professionals succeed at work.

Convert windows batch to robocopy

Starr Duskk
Starr Duskk asked
on
I'd like to convert this command to use Robocopy instead of Xcopy. I apparently might have paths that are too long. Getting insufficient memory errors with plenty of memory.

xcopy D:\Webs\WebSolution\*.*                   G:\BranchBups\Cleanups\Hourly\WebSolutionXXX%FILENAME%\*.* /e /Exclude:ExcludeHourly.txt

Can someone assist me with that? I can't find a robocopy equivalent to excluding files based on what is in the text file.

Thanks!
Comment
Watch Question

Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
I don't believe there is a capability in ROBOCOPY to get excluded file names/patterns from a text file like XCOPY.  You will have to list them individually on the command line, like:

robocopy /e D:\Webs\WebSolution G:\BranchBups\Cleanups\Hourly\WebSolutionXXX%FILENAME% /xf *.tx /xf *.tmp /xf desktop.ini

Open in new window


A work around is to create a "job" script for the ROBOCOPY and then edit it to include the list of files to exclude...  Here's an example I created here of the generated JOB file, notice multiple exclude patterns or names can be specified and you can edit this to add all yours.  Then just run the JOB file with ROBOCOPY like:

robocopy /job:myjob.rcj

Additional info on using ROBOCOPY JOBS can be found here:

Robocopy: The Ultimate Guide (A Complete How-To)

::
:: Robocopy Job B:\EE\TEMP\MYJOB.RCJ
::
:: Created by xxxxx on Thursday, February 6, 2020 at 3:29:55 PM
::

::
:: Source Directory :
::
        /SD:D:\Webs\WebSolution\        :: Source Directory.

::
:: Destination Directory :
::
        /DD:G:\BranchBups\Cleanups\Hourly\WebSolutionXXX%FILENAME%\     :: Destination Directory.

::
:: Include These Files :
::
        /IF             :: Include Files matching these names
::              *.*     :: Include all names (currently - Command Line may override)

::
:: Exclude These Directories :
::
        /XD             :: eXclude Directories matching these names
::                      :: eXclude no names (currently - Command Line may override)

::
:: Exclude These Files :
::
        /XF             :: eXclude Files matching these names
                desktop.ini
                *.txt
                *.tmp
::
:: Copy options :
::
        /S              :: copy Subdirectories, but not empty ones.
        /E              :: copy subdirectories, including Empty ones.
        /DCOPY:DA       :: what to COPY for directories (default is /DCOPY:DA).
        /COPY:DAT       :: what to COPY for files (default is /COPY:DAT).
::
:: Retry Options :
::
        /R:1000000      :: number of Retries on failed copies: default 1 million.
        /W:30           :: Wait time between retries: default is 30 seconds.
::
:: Logging Options :
::

Open in new window


»bp
NVITEnd-user support
CERTIFIED EXPERT
Commented:

In addition, the XCOPY /EXCLUDE switch lets you exclude files AND directories. So, if your file has these mixed, you'd have to use both the /XF for files and /XD for directories.

CERTIFIED EXPERT
Commented:
you can try adding this to your batch fiile

@echo off
setlocal enableextensions enabledelayedexpansion
set EXLIST=
for /f "delims=" %%v in (ExcludeHourly.txt) do (
 if {!EXLIST!} EQU {} (set EXLIST="%%v") else (set EXLIST=!EXLIST! "%%v")
)
echo %EXLIST%
endlocal

then use /XD %exlist%   in your robocopy command
Starr DuskkASP.NET VB.NET Developer

Author

Commented:
I haven't had a chance to try the solutions yet, but thanks everyone!