views:

648

answers:

3

I think I saw once that it was possible to use the functionality of windows' search feature(s) in code. That it was possible to search for files using a sql query (something like "select filename from filestore where directory = 'c:\somedir' and extention in ('.doc','.txt','.me') and datemodified >= '2009-01-01 00:00:00'"

Anyway, even if there isn't a way to do it with a query, is there any functionality in the Windows API OR any simple code for doing exactly this type of thing?

It seems such an obvious thing for there not to be an easy way to do it.

I have a function that finds all files in a dir (with subdirs) but it's basically dumb. It can't search with wildcards and it can't search with other criteria such as date newer than a given date.

If possible I don't want to download any 3rd party shareware libraries to do this. I'm using C++ builder in vista, and if there are any vista-only functionality for this then that's ok.

A: 

You can use FindFirstFileEx() to search with wildcards and attributes.

Stefan
Perfect. I'll try that when I get home (to my code)
MrVimes
OK I tried it. Seems it can't be used to search for wildcards or any other search criteria. It's no better than 'findfirst' or 'findfirstfile'. The paramaters for specifying criteria say 'reserved for future use' and must be null. the function dnt wrk nyw gn sk nw q. n mr spc fr cmt.
MrVimes
Yes, it can be used to search with wildcards. You must be doing something wrong if it doesn't work.
Stefan
+2  A: 

Actually, you can use FindFirstFileEx() to implement your search criteria. Unfortunately, most of the time you have to implement this yourself.. It isn't too hard..

Basically you can check the WIN32_FIND_DATA structure for criteria that you want to search for. For example, if you wanted to find only files with a creation date greater than a certain date, you would check if the WIN32_FIND_DATA structure member ftCreationTime or ftLastWriteTime, depending on your needs..

krebstar
A: 

The C code has been posted thousands of times on Google Groups since 90's ( news://comp.os.ms-windows.programmer.win32 and others )