Search code examples
batch-filebatch-processingxcopy

Xcopy command with exclude flag still brings excluded file


I want to copy all files/folders except a.txt file. The command that I use is like below: Xcopy C:\Data C:\NewData /q/s/d/i/h/y/EXCLUDE:C:\Data\a.txt

This command brings everything including the a.txt event though there is exclude flag for it. I am not sure what I am missing. Thank you for your help in advance.


Solution

  • The exclude option uses the file provided as a text file that contains the names of files or directories you wish to exclude one per line. So you need something like this:

    echo a.txt > mylist
    xcopy ... /exclude:mylist