Robocopy all files except with particular character in filename

11,384

I don't think robocopy supports regular expressions, but it does support wildcards (that is, the asterisk *).

So you'd include these wildcards when telling it what files to exclude using the /XF flag.

robocopy *.jpg C:\source C:\dest /XF *_*.jpg

This works if the _ is at the beginning, middle, or end of the file.

If you have multiple characters to wanted to exclude (say, exclude files that have underscores (_) and dashes (-)) then just add another wildcard statement after the /XF flag. You can list multiple parameters there, separated by spaces.

So something like

robocopy *.jpg C:\source C:\dest /XF *_*.jpg *-*.jpg
Share:
11,384
J3FFK
Author by

J3FFK

Updated on June 09, 2022

Comments

  • J3FFK
    J3FFK almost 2 years

    Using robocopy command I need to copy all files, but exclude files with particular character in the filename? For examlple copy all .jpg files with filenames containing underscore _ in it.

    I have tried this command, but it doesn't work:

    Robocopy C:\SourceFolder C:\DestFolder ^[^_]+.jpg$

    Could be something really simple I'm overlooking here, but what?

    There is also /XF flag to exclude certain file types, but (how) can it be used to exclude filenames containing the underscore in the filename?