Search code examples
batch-filexcopy

How to exclude a specific file from being copied using xcopy


I'm new to Windows batch files, but I'm writing a .bat file that just copies a bunch of files from one place to another maintaining the file directory structure. Using xcopy this is simple but I need to exclude some files from being copied. You can use /exclude and create a text file full of strings that you want to be excluded, but this doesn't just exclude files with the exact names in the text file, it excludes all files whose filenames contain any of the strings in the text file.

What this means is, if I want to exclude any files named 123.txt and put this string in my exclusions text file, if there was a file called 1123.txt anywhere in the source folder or any of its subfolders that would also be excluded.

How can I exclude only files with a specific filename from being copied?


Solution

  • Evening Bill.

    Can you add a slash before each file name? That should work

    EG

    instead of

    123.txt

    blah.txt

    use

    \123.txt

    \blah.txt