I've pretty much got my file-finder program working. Motivation for this was the fact that my Explorer is totally broken when it comes to searching for files. Does nothing. Totally useless. (My whole computer is pretty fucked up, Windows 7 with many many problems.) So I wrote this. Learned a lot along the way. I'm attaching source and all for any curious onlookers.
It works but has a couple issues:
- Long and/or deep searches cause some of the file icons to be corrupted. To see this, try doing a search first on .dll (this will find a shitload of files; 51,679 on my system. No wonder things are so screwed up! Too much complexity there!) Then try doing another search (I've been using "test"). You should see some black squares instead of file icons. I have no idea why this is happening. Not a deal-breaker but highly annoying.
- Listview control gets screwed up, strangely. After a couple searches the first item gets partially covered; you can't scroll all the way up to see it.
The "find" field is implicitly wildcarded; i.e., test = *test*. That part works pretty reliably well.
A "text" search will search files for a text string, similarly wildcarded. Can be case sensitive or not. (All file searches are case-insensitive, per the file system.)
In case you're wondering about what I call the "flicker" field which comes up during a long (> 4 sec.) search and shows filenames flashing by, this was supposed to be a progress-bar control. It worked OK, except that on long searches it would stop moving (the
PBS_MARQUEE behavior). This is another mystery to me. The static control works reliably, even though it's possibly more annoying to the user. I wanted something that would show the user that something is actually happening, that the damn thing isn't frozen.
Note: The source has one include file which is a memory dialog template (produced by another of my tools, DialogGen; if interested, I could post that here as well, though it's complicated). Otherwise pretty straightforward stuff.
What did I learn from writing this?
- Thread execution (file-finder runs in a worker thread so UI isn't crippled)
- Using SHGetFileInfo() to retrieve file icons
- Weird file system stuff
What weird file system stuff? Well, for one thing, I discovered that FindFirstFile() and FindNextFile() will give me what are basically bogus files whose names are ':'. That's right; as we know, that's a totally "illegal" character for a filename. And yet you'll see those files if you do a full recursive scan of your filesystem. They occur in certain Windows folders; I think they are actually what they call "junctions" instead of real files. So I just filter them out and ignore them. (The file size fields for these "files" are set to some really wacky values.)