July 21st, 2005

FindFirstFile is not a SQL query

The FindFirstFile function is not a SQL query. It’s a very simple directory enumerator. There is a slightly fancier version called FindFirstFileEx, but even that function doesn’t add much at present beyond filtering for directories or devices.

You don’t get to pass it sort criteria like or “return the files/directories sorted smallest file first”, or “return the files/directories in reverse order of creation” The only filtering you can provide are the wildcard pattern and (if you use FindFirstFileEx) a directory filter. The wildcard language is very limited as well; it can’t express queries like “files whose extension are either .exe or .dll” or “all files whose extension is .c plus all directories regardless of extension“. You also can’t ask it questions like, “Tell me the total size of the files in this directory”, for as we saw earlier, this question is underspecified.

If you want to do any of those advanced queries, you’ll have to code it up yourself. Or as Hippie Tim is fond of saying, “Start typing!”

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.