替换 findfirst() 和 findnext()
是否有 findfirst()
和 findnext()
的替代品。 我使用的是 microsoft Visual C++ 2010 express
,它不支持这些函数,头文件
也不支持?
我想使用这些函数来计算目录中的文件数量,但是没有这些函数我遇到了问题。
如果没有替代上述功能还有其他办法吗? ?还有其他一些功能吗?
Is there any replacement for findfirst()
and findnext()
.
I am using microsoft visual c++ 2010 express
and it doesn't support these functions neither the header file <dir.h>
?
I was looking to count the number of files in the directory using these functions but i am having a problem without these functions.
If there is no replacement of the mentioned functions is there any other way out. ? Some other functions ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如“iammilind”在评论中所说(可能值得回答) - 您可以使用 Windows api 的 FindFirstFile 和 FindNextFile 函数,您只需填写一个结构体并迭代后者,直到到达无效句柄。这些函数确实可以在控制台上运行,但您必须包含“Windows.h”标头。
然而,这些函数确实存在一些缺陷,如果您希望代码在 Windows 以外的任何设备上运行,您最好使用另一个标头/库(例如 vBx 提到的 Boost::Filesystem)。
另外,这可能会有所帮助:
C++ - 加载全部文件名+统计当前目录下的文件数+过滤文件扩展名
As 'iammilind' said in the comments (probably worthy of an answer) - you can use the windows api's FindFirstFile and FindNextFile functions, you just have to fill up a struct and iterate through the latter until you reach an invalid handle. These functions do work on console, but you must include the 'Windows.h' header.
These functions do come with a couple of pitfalls however, and if you want your code to run on anything other than windows you're probably better off using another header/library (such as Boost::Filesystem, mentioned by vBx).
Also, this may be of help:
C++ - Load all filename + count the number of files in a current directory + filter file extension
您可以使用 Boost.Filesystem那
You can use Boost.Filesystem for that
在 Windows 中,您可以使用:_findnext、_findnext64、_findnexti64、_wfindnext、_wfindnext64、_wfindnexti64
In Windows you can use: _findnext, _findnext64, _findnexti64, _wfindnext, _wfindnext64, _wfindnexti64
如果您使用 MinGW Developer Studio,这可能会有所帮助:
假设您要查看的目录中有文件:
与模式“s*”匹配的两个文件的代码将是:
If you use MinGW Developer Studio, this might help:
Assuming that you have the files in the dir you want to look will be:
The code for the two files matching the pattern "s*" will be: