File filter with regular expressions
As of version 0.7.4, Capivara supports file filters in the synchronization process. What does that mean? It is now simply possible to create regular expressions in order to build a white list and a black list of files which are going to be synchronized or not, respectively.
What you need to know is
A regular expression tries to match the relative path. Example: Let’s assume we have 2 directories to synchronize
/home/user/x/y and /foo/x/y
and you entered the directories
/home/user and /foo
and you want to exclude directory ‘y’ you would add
to the exclude list.
I am aware of the fact that no user is going to read documentation. So, I think it’s best to provide many useful examples.
- .*\.mp3 (dot asterisk backslash dot mp3) matches any mp3 file
- foo/.*\.tex matches any tex file in directory foo
- .*/CVS(/.*)? matches any CVS directory
- .*/[.]git(/.*)? matches any .git directory
What is an include / exclude list?
Short answer. The include list contains all files which will be synchronized (with exceptions). The exclude list contains all files which are definitely out of the synchronization (no exception).
Let’s look closer at the include list. Assume that I want to synchronize my mp3 files only. So, I add a regular expression that matches an mp3 file to the include list (see below). That’s it! (but note: a directory gets inserted to the include list automatically when it contains included regular files)
A note by the developer
I know that writing regular expressions seems to be pretty odd for user who haven’t gotten in touch with regex before. At the same time the question for ‘why regular expressions’ comes up. The answer is: Java supports regular expressions and not something else which means there is no support for simpler expression types. I didn’t want to write my own pattern matcher and therefore stick with the Java classes. Hence, I experimented with processing simple patterns which I had to convert to Java regular expressions. This resulated in a lot of trouble since I wanted to keep the support for regular expressions as well. In the end, I decided that I will use Java regex, period. If there will be users complaining I might change it in the future...