Search Through File Names

Normally, the File Selector is used to determine which files are included in the action, and the search terms on the Action panel are used to search through the contents of those files. But if you want to run a quick search through file names or file paths, you can set the “action type” on the Action panel to “file or folder name search”. Then the search terms in the main part of the action are used to search through the names of the files rather than their contents.

  1. Clear the file selection.
  2. Click on the folder that contains the files you want to search through. Then select Include File or Folder or Include Folder and Subfolders from the File Selector menu.
  3. Repeat step 2 if you want to search through the files in multiple folders.
  4. Set “archive formats to search inside” to “(unused)” if you want to search through the names of archives (treating them as ordinary files). Set it to “None” if you do not want to search through the names of archives. Set it to “All archives” if you want to search through the names of the files inside the archives (treating the archives as folders).
  5. Start with a fresh action.
  6. Set the action type to “file or folder name search”.
  7. Set “what to search through” to “file names only”.
  8. Enter one or more search terms to look for in the file names.
  9. Click the Preview button to run the action.

The Results panel will show a list of files of which the names contain one or more of the search terms from step 7. If you want to get a list of files not having any of the search terms in their names, turn on the “invert results” checkbox on the Action panel after setting the action type to “file name search”.

This file selection and action are available in the PowerGREP5.pgl library as “Search through file names”.

Using The File Selector to Search Through File Names

For complex operations where you want to use an action type other than “file or folder name search” so that you can search through or manipulate the contents of the files, you can use the File Selector to include or exclude certain files by searching through their names. This example uses the “list files” action type without the search term to demonstrate how searching though file names using the File Selector works.

  1. Clear the file selection.
  2. Click on the folder that contains the files you want to search through. Then select Include File or Folder or Include Folder and Subfolders from the File Selector menu.
  3. Repeat step 2 if you want to search through the files in multiple folders.
  4. Set “archive formats to search inside” to “(unused)” if you want to search through the names of archives (treating them as ordinary files). Set it to “None” if you do not want to search through the names of archives. Set it to “All archives” if you want to search through the names of the files inside the archives (treating the archives as folders).
  5. Turn on “use regular expressions to define masks”, even if you want to search for a simple word or phrase.
  6. Enter your search terms in the “include files” box, delimited by semicolons.
  7. Start with a fresh action.
  8. Set the action type to “list files”.
  9. Leave the Search box blank.
  10. Click the Preview button to run the action.

The Results panel will show a list of files of which the names contain one or more of the search terms from step 6.

If you want to get a list of files not having any of the search terms in their names, enter the search terms from step 6 in the “exclude files” box instead. If you enter search terms in both boxes, you will get a list of files having one or more search terms from “include files”, and none of the search terms from “exclude files” in their names.

To search for different file names in different folders, turn off “same masks for all folders”. Then click on a folder to specify “include files” and “exclude files” for that folder only. Repeat for all other folders you marked in step 2.

How to Search through Both Names and Contents

To search through both the names of the files, and their contents, go through steps 1 through 7 above to make the file selector search through the file names. You should not select “(unused)” in step 4 though. Treating archives as ordinary files does not produce proper search results when searching through the contents of files. Choose “None” to skip archives, or choose another configuration to search through the contents of the files inside (some) archives. Then proceed as follows:

  1. Leave the action type as “simple search”.
  2. On the Action panel, enter the search terms you want to search for through the contents of the files.
  3. Click the Preview button to run the action.

PowerGREP will then search through the contents of those files of which the names contain one or more of the search terms from step 6. A file will only be listed in the results if both its name matches the terms of step 6, and its contents match the terms of step 9.

PowerGREP cannot produce a list of files that contain a search term in their name, or contain the search term in their contents, but do not contain the search term in both name and contents. You will need to run two searches. One where you enter the search terms in the “include files” box and leave the search terms on the Action page blank, and another where you leave “include files” blank and enter the terms on the Action page.

This file selection and action are available in the PowerGREP5.pgl library as “Search through file names and file contents”.