Searching files on Windows

Searching files on Windows is a pain. The built-in search features don’t find everything. There may be ways to make them work, but I haven’t persisted long enough to make them work.

On Linux, the combination of find, xargs, and grep works well, and sometimes it works on Windows using the GOW or GnuWin port of these tools. Again there may be a way to make the ported utilities work more as expected, though I haven’t found it. I suspect the problem isn’t with the tools per se but their interaction with the command line. I also tried Emacs features like rgrep, but these features use the ported find and grep utilities, and so you run into the same problems with Emacs as you do running them directly and more.

Ack logo

It looks like ack is the way to go. I heard about it a long time ago and kept meaning to try it out. Now I finally did. It’s fast, convenient, etc. But here are the two things I most like about it:

  1. Ack works the same across platforms.
  2. Ack uses Perl regular expression syntax.

While the alternatives above are supposed to work the same across platforms, they don’t in my experience. But ack does because it’s a pure Perl program. All the portability has been delegated to Perl, where it is well handled. I imagine once I become more familiar with ack I’ll prefer it on Linux as well.

Because it’s a Perl program, ack uses Perl regex syntax. Perl has the most powerful regex implementation out there, though I seldom need any features unique to Perl. More important for me is that Perl regular expression dialect is the one I remember most easily.

More regular expression posts

10 thoughts on “Searching files on Windows

  1. I use a small freeware called “Windows Grep”. It has a nice GUI, can be powerfully configured, and is reasonably fast. If you need more than just searching for file names, that’s the way to go for me.

  2. I remember well the day many years ago (either win95 or winxp) when I discovered that Windows file manager search was not searching in files for which it did not have a program registered with that files extension. That is to say, if .java file extension was not registered to be opened by a specific program, then searching in the file manager would not show any results of text matching within .java files. I simply could not believe it, but it was true. I assume this has since been fixed, I hope, but what a bad taste it leaves in ones mouth.

  3. Thanks for the mention, John. I’m glad you’ve found ack useful.

    It’s gratifying to hear a Windows user appreciate the pure-Perl portability of ack because that’s one of the principles I’ve stuck to. There have been a number of suggested changes I’ve had to turn down over the years because it would break Windows compatibility.

    The previous commenter seems to be alluding to a behavior of ack 1.x where ack would not search files of an unknown filetype. This behavior has changed in ack 2.x so that ack searches all text files by default. However, it will still never search binary files.

  4. On Windows, I’m fond of voidtools’ “Everything”, which keeps an index of all files (you can specify drives/directories to include/ignore), and let’s you search them with a glob-like search or regex.

    There’s no command line option so far as I know, but I can invoke it and then search without any mouse input, so that’s good enough for me.

  5. Leigh Hebblethwaite

    I would like to also mention Voidtools Everything. The tool does one thing but does it very well. It reports filenames that match a string or regular expression. The search is very fast.

    It searches an index of names. However, the index is built from the Windows MFT. The indexing process is very fast *and* the index is kept up to date in real time.

    Responding to the previous poster, there is a command line interface. It is called es. It is a separate download that is available from the website. Try “es -h”.

    I used es to build a command line tool, in Perl, called esgrep. This uses es to obtain a list of matching filenames and then applies Perl’s File::Grep to the list.

  6. Two other posters have already mentioned it, but I just can’t pass up this opportunity to talk about how amazing Everything by Voidtools is. I’ve been programming since the mid-90s, and this is the *best program I have ever used*, bar none. It’s changed the way I use my computer: I now give files very (gratuitously?) long filenames, and when I need a file, I hit Win+F (which I’ve remapped to start Everything) and just start typing parts of the file’s name. 10x faster than trying to remember the windy path of directories I would need to follow to get to it with Explorer.

    As pointed out by Leigh Hebblethwaite, its initial indexing uses the NTFS MFS on-disk structure to quickly (a few seconds for an entire 250Gb drive) build the index the first time. Thereafter it watches for directory changes in the background. When you start a search, you’re shown a list of *every file on your computer*, and typing a character immediately (yes, immediately — even on my old WinXP laptop bought in 2007) filters the list to include only filenames that contain that character. You can also use regexes, turn case sensitivity on/off, narrow by ancestor directory, etc., all with a very intuitive and minimalist syntax.

    And the whole program is just 463Kb! No framework bloat — it’s clearly just tight, plain Win32 API C code. I’m very fussy about software doing unnecessary stuff in the background, but Everything’s directory watching introduces no noticeable overhead. You can tell immediately it’s just a well-made thing, and a joy to use.

  7. One thing I should point out though: Everything searches only file *names*, not contents. So it’s not a complete replacement for the likes of ack or Windows Search.

Comments are closed.