Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robocopy all files except with particular character in filename

Tags:

regex

robocopy

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?

like image 329
J3FFK Avatar asked Nov 28 '15 12:11

J3FFK


People also ask

How do I exclude a specific file in Robocopy?

The most important switches in this command are the /XD which allows you to exclude folders, and /XF that you can use to exclude files. The other options are optional, but you should use these options that you should use in any standard copy process using Robocopy.

Does Robocopy skip identical files?

In other words: Robocopy considers two files to be the same based only on whether their last-modified time stamps and file sizes are identical and therefore skips copying in that event.

What is Copyall in Robocopy?

Source Options /S - Copy subfolders. /E - Copy subfolders including empty folders (useful for recreating a folder structure) /COPYALL - Copy all file info, such as attributes and timestamps. /MAXAGE & /MINAGE - Use these to filter the file ages, either maximums or minimums.

Is Robocopy faster than File Explorer?

While these are good options, depending on the amount of data you have to transfer, the process can take a long time using File Explorer. If you want to copy a lot of files faster and more reliably, you need a better solution, such as Robocopy.


1 Answers

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
like image 61
romellem Avatar answered Oct 14 '22 07:10

romellem