Action Part: Filter Files

Filter files

The “filter files” action part is available for all action types except “simple search”. It enables you to use an extra set of search terms to filter out files. The “filter files” drop-down list gives you four choices:

Filtering files is always done by searching through the contents of files. Even for “file or folder name search”, “file or folder name collect”, and “rename files or folders” actions where the main part of the action searches through the file’s name. If you want to filter out files based on their file names, use the “exclude files” box on the File Selector panel.

There are no options to specify other than the search terms you want to filter with. Matches found by the “filter files” action part never show up on the Results panel. If a file is filtered out, it is indicated in the results as not having any search matches, regardless of whether it was filtered with “disallow any terms to match” or “require one/all terms to match”. If a file is not filtered out, the results show its search matches as usual, if any are found by the main part of the action.

A And Not B

A and not B

To get a list of files that contain “A” but not “B”, set the “action type” to “list files”. Specify A as the search term in the main part of the action. Set “filter files” to “disallow any terms to match” and specify B as the search term to filter with.

If you do this with the “search” action type, you’ll get a list of all the occurrences of A in all the files that do not contain B.

Example: Boolean operators “and” and “or”

Capture Text for Reuse

Rename Files Based on HTML Title Tags

When using regular expressions, named capturing groups carry over from the “filter files” part of the action to all the other parts. This means you can use the “filter files” part to run an extra search to capture a part of the file. The filter doesn’t necessarily have to exclude any files. You can then search for that part elsewhere in the file by using a backreference to that named capturing group in the regular expression in the main part of the action. Or you can insert that part somewhere by using a backreference in the replacement string in the main part of the action.

You can even capture multiple parts of the file by using a list of regular expressions with a differently named capturing group in each regular expression. Set “filter files” to “require all terms to match” and turn off “non-overlapping search”. These two settings ensure PowerGREP searches through the entire file once using each regular expression in your list, filling the named capturing group(s) of each regular expression, provided they can all find a match in the file.

Named capturing groups also carry over when “filter files” works on the contents of files (which it always does) and the main part of the action works on file names (which it does for “file or folder name search”, “file or folder name collect”, and “rename files or folders” actions). This allows you to search through the file’s name for something found in the file’s contents, or collect part of the file’s name along with part of the file’s contents, or change the file’s name to something found in its contents. The screen shot shows an example of using this technique to rename HTML files to their titles or top-level headers.

Examples: Rename Audio Files Using Meta Data, Insert proper HTML title tags and Rename files based on HTML title tags