Search code examples
windowscmdxcopyrobocopy

converting xcopy to robocopy


Tried to use xcopy and excluding a folder and all its subfolders.

C:\Merged\org\a>xcopy /I /E /Y C:\Merged\org\*.* C:\Merged\dest /exclude:"C:\Mer
ged\org\a\*.*"
Can't read file: "C:\Merged\org\a\*.*"

I guess I cannot exclude folder, but only file with xcopy.

So I think of moving to robocopy, but I'm not sure which flags to use.

What is the equivalent robocopy to my above xcopy ?


Solution

  • Well, you can. Read up on XCOPY /?:

    /EXCLUDE:file1[+file2][+file3]... Specifies a list of files containing strings. Each string should be in a separate line in the files. When any of the strings match any part of the absolute path of the file to be copied, that file will be excluded from being copied. For example, specifying a string like \obj\ or .obj will exclude all files underneath the directory obj or all files with the .obj extension respectively.

    The problem is you specify the path you want to exclude to /EXCLUDE when you should specify the name of a file, which contains the "paths" to exclude (it is actually more flexible see above). The error message you get even hints at that.

    Create a file, e.g. C:\ignore.txt, that contains the line "C:\Merged\orga\a\", then invoke XCOPY as follows:

    xcopy.exe C:\Merged\org\*.* C:\Merged\dest /exclude:C:\ignore.txt /I /E /Y
    

    If you want to use robocopy nevertheless, you can do so like:

    robocopy.exe c:\merged\org c:\merged\dest /xd c:\merged\org\a /IS /E