How to filter items by location or sub-folder


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.

Three ways to filter by location:

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:

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 only a literal dot. (Easy to forget to do that with extensions.)

  1. 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.

  2. Expanding on that, 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\*

  3. 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.

The folder five with full path C:\one\two\three\four\five has a location of C:\one\two\three\four, which matches *\*\*\*. This means 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.

Alternatively, you can use this Script Column which reports path depth as a number which you can filter on:

1 Like