windows版本
参考https://www.cnblogs.com/wqpkita/p/6849283.html
// windows下遍历指定目录下的所有文件
void listFiles(const char * dir)
{
char dirNew[200];
strcpy(dirNew, dir);
strcat(dirNew, "\\*.*"); // 在目录后面加上"\\*.*"进行第一次搜索
intptr_t handle;
_finddata_t findData;
handle = _findfirst(dirNew, &findData);
if (handle == -1) // 检查是否成功
return;
do
{
if (findData.attrib & _A_SUBDIR)
{
// 去除.和..目录,.表示当前目录,..表示上一级目录
if (strcmp(findData.name, ".") == 0 || strcmp(findData.name, "..") == 0)
continue;
cout << findData.name << "\t<dir>\n";
}
else
cout << findData.name << "\t" << findData.size << " bytes.\n";