Special Characters in Find Files Dialog

The Windows 95 shell provides a user interface for searching through files and folders on the local machine. The Windows Explorer gives access to this feature through the Start menu, through the Tools menu of any window that is opened for browsing folders, and through the keyboard shortcut F3 while any Explorer window (including the task bar and the desktop) has the focus.

A dialog box is used to get the search parameters, to stop, start and reset the search, and to present results. The only files found by the search are ones that satisfy all the given constraints. Of particular interest here is that users may ask for files that contain particular text.

Problem

Text entered in the edit box alongside “Containing text:” is not necessarily the text that the Shell uses in its search. Some characters have special meanings, which may be a surprise to users who happen to need these characters in the search text.

Details

The backslash has special significance when it is followed by any character that is not alphanumeric. A backslash in this position is ignored. If the character that follows would otherwise have special significance, then that character is instead interpreted without its special significance.

The dollar sign has special significance when given as the last character of the search text. In such a position, a dollar sign is interpreted to mean that the preceding text is required to appear at the end of a line in any file being searched. In effect, a trailing dollar sign in the edit box is a carriage-return for the search.

Implications

To search for files containing text that ends with a dollar sign, insert a backslash immediately before the dollar sign. For example, if searching for documents that contain the string “cost me $” because you have forgotten the cost but know that you mentioned it in one of the documents, enter “cost me \$” in the Find Files dialog box. You may notice that the dialog box’s title is something like “Find: Files containing text cost me \$” (with the backslash). However, the reality is that the search will be to find files containing text “cost me $” (because the backslash is ignored).

To search for files containing text that includes a backslash, double the backslash so that the second backslash in the pair is interpreted literally.

Cause

Although the dialog box and the search are ordinarily started as an option in the Windows Explorer program, they are implemented in SHELL32.DLL. A standard Find Files dialog and search are actually available to any program that calls the SHFindFiles function in SHELL32. This function is not documented and is exported only by ordinal, but Microsoft’s name for it is knowable from the SHELL32.LIB import library supplied with the Win32 SDK. (The function eventually got documented among the Settlement Program Interfaces in late 2002.)

SHELL32 implements a generalised text-searching engine, but at least for now, the SHELL32 code that handles the Find Files dialog box uses only one of this engine’s many options, namely the choice of whether searches should be case-sensitive. Other features of the text-searching engine, and most notably the support for matching searched text against regular expressions, are not used.

The dollar sign and backslash are just one of many non-alphanumeric characters with special significance in regular expressions. The special meanings that these characters have in the Find Files dialog are precisely their special meanings in regular expressions. Inspection of the relevant SHELL32 code confirms that even though the engine is used only for simple searches, the dollar sign and backslash are interpreted as for regular expressions.

Digression

Another property of the text search that may interest, if only because of its potential to surprise, is that when searching for files containing some given text, files that have the system attribute are ignored. If the search is conducted with all the other constraints unchanged but without requiring files to contain the given text, then system files are included in the search.