以下代码枚举windows的目录结构:
void EnumDirectory(TCHAR * strPath, unsigned int deepth)
{
unsigned int i;
HANDLE hFind;
WIN32_FIND_DATA findData;
TCHAR path[1024];
TCHAR tmpPath[1024];
hFind = FindFirstFile(strPath , &findData);
do
{
if (hFind == INVALID_HANDLE_VALUE)
{
break;
}
for ( i=0 ; i<deepth ; i++ )
{
printf(" ");
}
if ((findData.dwFileAttributes&(FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_ARCHIVE)) != 0)
{
printf("%s/n" , findData.cFileName);
}
else if ((findData.dwFileAttributes&(FILE_ATTRIBUTE_DIRECTORY)) != 0)
{
printf("%s/n" , findData.cFileName);
if (strcmp(findData.cFileName , ".")!=0 &&
strcmp(findData.cFileName , "..")!=0)
{
strcpy(tmpPath , strPath);
tmpPath[strlen(strPath)-1] = '/0';
tmpPath[strlen(strPath)-2] = '//';
_stprintf(path , "%s%s//*" , tmpPath , findData.cFileName);
EnumDirectory(path , deepth+1);
}
}
} while(FindNextFile(hFind , &findData));
return;
}
试试看:
void main()
{
EnumDirectory("D://3.0//CareLand_Navigation2_6//*" , 0);
}