Skip to content

Using FileSharper

Andrew Vardeman edited this page Feb 17, 2018 · 15 revisions

Introduction

Without adding any custom code to FileSharper, you can use it as a general-purpose file search and processing tool with features found in DOS and UNIX command-line tools. You can define searches that mix and match search conditions and apply a chain of processing steps much as you would do with a command-line script. What follows is an overview of how to set up and run a FileSharper search.

Launching FileSharper

FileSharper binaries are currently being published via ClickOnce to http://www.flamingtortoise.com/FileSharper/Download. If you have installed FileSharper, you should be able to launch it from the Start menu.

If you plan to add functionality to FileSharper or don't trust the binaries, you should be able to clone the repository, open the solution in Visual Studio, set FileSharper as the startup project, and click "Start" to build and run. (The first build may take a while because NuGet packages must be downloaded.)

FileSharper will look something like this:

FileSharper at startup

Selecting a File Source

FileSharper allows you to select a "file source," which provides the list of files to test and process. Typically, to search through the filesystem, you will select "Directory Search." By default, this will search your entire C drive recursively for all non-hidden and non-system files:

Directory Search

You can modify the search directory, the file pattern, and other settings in the property editor. To change the directory, you can manually edit the path or click the "..." button to use a standard Windows file open dialog.

There are other, more special-purpose file sources available for searching through a known list of files. The "File" file source will read that list from a file, and the "List" file source will allow you to enter the file list in a textbox.

Specifying the Search Condition(s)

You can specify zero or more search conditions for matching files. If you don't specify a search condition, every file provided by the file source will be treated as a match. You can, instead, select a single condition from the menu or select a compound condition like "All" or "Any" to specify a list of conditions to test. The condition menu looks like this:

Condition Menu

Below is an example compound condition built from two other conditions. It will match all files that are not read-only and contain text matched by the case-insensitive regular expression "hello.*world":

Compound Condition

If you are familiar with UNIX command-line tools, you will note that the search as specified so far is similar to a combination of the find and grep tools. This means FileSharper can function as a poor man's grepWin. The advantage of FileSharper is that arbitrarily complex search conditions can be built, and it's easy to add your own search conditions in code.

Specifying Additional Fields

The FileSharper UI displays a table of search results that can also be written to a CSV file. The table contains each file's path and relevant fields produced by the search conditions. You can add additional fields by selecting items from the "Additional Fields" menus. Here two additional fields (Line Count and Word Count) have been specified:

Additional Fields

Specifying Processors

You can specify file processors to run either on all files tested or only the files matched by the condition. Typically, you'll be interested only in matched files. To specify processors for matched files, use the menus in the "When Matched..." groupbox. In the screenshot below, two processors have been specified: "Write to CSV" and "Open Containing Folder." The first processor will generate the CSV logfile mentioned in the previous section. The second will open an Explorer window for each directory in which a match is found. Each processor takes as input the original file (as opposed to intermediate files generated by other processors).

Matched Processors

Saving a Search

You can save a search for later use via the Save menu item in the File menu.

Running a Search

To run a search, click the "Search" button. Results are shown in the grid at the bottom of the window:

Running a Search

You can limit the number of results that are shown in the grid by changing the number in the text box labeled "Display only first." This only affects the user interface and not the search itself. To limit the number of results from the search itself, check the "Stop after" checkbox and enter a number.