Windows API 方式在 C++ 中使用通配符和其他条件搜索子文件夹?
我想我曾经看到可以在代码中使用 Windows 搜索功能的功能。 可以使用 sql 查询搜索文件(类似于“从文件存储中选择文件名,其中目录 = 'c:\somedir' 和扩展名 ('.doc','.txt','.me') 和 datemodified >= '2009-01-01 00:00:00'"
无论如何,即使没有办法通过查询来完成此操作,Windows API 中是否有任何功能或任何简单的代码可以精确执行此类型 我
这似乎是一件显而易见的事情,因为
有一个函数可以查找目录中的所有文件(带有子目录),但它基本上无法使用通配符进行搜索。无法使用其他条件进行搜索,例如比给定日期更新的日期
如果可能的话,我不想下载任何第三方共享软件库来执行此操作,我在 vista 中使用 C++ 构建器,并且如果有任何 vista-只有这个功能就可以了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,您可以使用 FindFirstFileEx() 来实现您的搜索条件。 不幸的是,大多数时候你必须自己实现这个..这并不太难..
基本上你可以检查 WIN32_FIND_DATA 结构,用于查找要搜索的条件。 例如,如果您只想查找创建日期大于特定日期的文件,则可以根据您的需要检查 WIN32_FIND_DATA 结构成员 ftCreationTime 还是 ftLastWriteTime。
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..
您可以使用 FindFirstFileEx() 进行搜索通配符和属性。
You can use FindFirstFileEx() to search with wildcards and attributes.