Since this guide was written, the ability to filter by Full Path was added. You can now apply wildcards and regexps to each file's full path in one line. This is sometimes easier than separately testing the filename and the parent folder's path.
Everything below still works, and the fundamentals remain the same, but you might want to consider using Full Path instead of Location in some cases. Of course, which is best depends on exactly what you are doing, and using Location is still better in some cases.
This post explains how to use Location and Subfolder clauses to filter items based on their directory path. It's in the form of a question & answer.
ezme wrote:Hi -
I have made a selection filter that only selects numbered files, but I need to skip files in subfolders named "old". I just can't seem to get the Location OR the subfolder clauses to work in flat view.
Name > match > [0-9]+.png (in regular expression mode)
Location > No Match > old (in wildcard mode)
But nothing gets selected. If I remove the Location clause, all numbered files gets selected like they should.
How do I use the Location or subfolder clauses properly?
Here are three slightly different ways to do it.
In all of them the filename regexp was changed from [0-9]+.png to [0-9]+\.png since, in regexps, . means "match anything" and you have to escape it to \. to match a literal dot. (Easy to forget to do that with extensions.)
- The first example is the most simple. The important difference to what you were doing is it matches on *\old, not just old, since the Location is a full path, not just the parent folder's name.
- Note that the first example will not exclude things which are in a subdirectory of "old" (unless the subdirectory is also called "old"). This second example corrects that problem and excludes everything in or below any folder called "old". If you expand the wildcards it is excluding both *\old and *\old\*
- Now for the final example. This will match exactly the same things as the previous example, but it is more efficient:
If you use a Subfolder clause then Opus will not even enter any folders called "old", which will speed things up a lot if there are a lot of things below the folders you want to skip over. On the other hand, if you use a Location clause instead of a Subfolder clause then Opus still goes through each and every file & directory testing its Location against the rules.
So the third example is the best one but I included the others so you can see how the Location clause works. Both Location and Subfolder are useful in different circumstances.
Note about Synchronize: Subfolder clauses do not currently work with the Synchronize tool in Opus. If you're using the filter there you should use Location clauses instead.
Bonus topic: Restricting the search depth
- People sometimes want to limit the search depth so that deeply nested folders are ignored. Building on what we used above, Opus can be told not to look inside sub-folders whose locations have too many \ characters in them.
The Location clause tests the full path to the parent of an item.
C:\one\two\three\four\five has location C:\one\two\three\four which matches *\*\*\* and means that the five folder (and any below it) will not be entered when searching.
Remember that Location is always an absolute path. If you want to limit the depth relative to where your search starts from then you'll have to adjust the wildcard string.