首页 > 代码库 > _findfirst和_findnext
_findfirst和_findnext
1、首先是_finddata结构体,用于存储文件信息的结构体。
2、_findfirst函数:long _findfirst(const char *, struct _finddata_t *);
第一个参数为文件名,第二个参数为_finddata结构体指针,若成功,则返回文件的句柄。
3、_findnext函数:int _findnext(long, struct _finddata_t *);
第一个参数为文件句柄,表示读下一个。
4、_findclose()函数:int _findclose(long);
将该文件句柄关闭
以下为一个小例子
void getFiles(string path, vector<string>& files)
{
long hFile = 0;
struct _finddata_t fileinfo;//存储文件信息的结构体
string p;
//c_str将string转为C下的字符,hFile得到的是文件句柄
if ((hFile = _findfirst(p.assign(path).append("\\*.jpg").c_str(), &fileinfo)) != -1)
{
do
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
参考:http://blog.sina.com.cn/s/blog_53988e5a0101dvlf.html
http://blog.csdn.net/samylee/article/details/53467668
_findfirst和_findnext
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。