参考博客https://blog.csdn.net/u012816621/article/details/48475885
运行环境VS2017及以后,报错,更改一个参数longf数据类型后正常。
#include <iostream>
#include <string>
#include <io.h>
using namespace std;
int main(int argc, char** argv)
{
_finddata_t file;
//long longf;
intptr_t longf;
string tempName;
//_findfirst返回的是long型; long __cdecl _findfirst(const char *, struct _finddata_t *)
if ((longf = _findfirst("d://*.*", &file)) == -1l)
{
cout << "文件没有找到!";
return 0;
}
do
{
cout << "文件列表:";
tempName = file.name;
if (tempName[0] == '.')
continue;
cout << file.name;
if (file.attrib == _A_NORMAL)
{
cout << " 普通文件 ";
}
else if (file.attrib == _A_RDONLY)
{
cout << " 只读文件 ";
}
else if (file.attrib == _A_HIDDEN)
{
cout << " 隐藏文件 ";
}
else if (file.attrib == _A_SYSTEM)
{
cout << " 系统文件 ";
}
else if (file.attrib == _A_SUBDIR)
{
cout << " 子目录 ";
}
else
{
cout << " 存档文件 ";
}
cout << endl;
} while (_findnext(longf, &file) == 0);//int __cdecl _findnext(long, struct _finddata_t *);如果找到下个文件的名字成功的话就返回0,否则返回-1
_findclose(longf);
system("pause");
return 0;
}
版权声明:本文为CSDN博主「DafuTT」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u012816621/article/details/48475885