下面是有问题的代码:
/*
有问题的程序,不能完成查询。如查询根目录时查询会出错。
*/
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
void findFile(char *path)
{
char str[256] = { 0 };
sprintf(str, "%s\\*.*", path);
BOOL res = TRUE;
WIN32_FIND_DATA fd;
HANDLE hf = FindFirstFile(str, &fd);
while (res)
{
printf("%s\n", fd.cFileName);
if (strchr(fd.cFileName, '.')==NULL)
{
char temp[256] = { 0 };
sprintf(temp, "%s\\%s", path, fd.cFileName);
findFile(temp);
printf("\n>>>>>>>>>>>\n");
}
res = FindNextFile(hf, &fd);
}
}
void main()
{
findFile("e:\\c_c++\\");
//下面的查询根目录不行
/*findFile("g:\\");*/
//findFile("c:\\");
system("pause");
}