请问下各位高手:用C语言如何实现“统计一个文件夹中的文件数目”?小弟先谢谢了!!!

是程序实现哦!!!!!谢谢!!1
2024-11-28 12:11:23
推荐回答(1个)
回答1:

#include
#include

using namespace std;

void func(LPTSTR fileName)
{
char sz[MAX_PATH];

lstrcpy(sz,fileName);

WIN32_FIND_DATA wfd;

HANDLE hFind;

TCHAR szF[MAX_PATH];

lstrcpy(szF,sz);

lstrcat(sz,"\\");

lstrcat(sz,"*.*");

hFind = FindFirstFile(sz,&wfd);

if(hFind == INVALID_HANDLE_VALUE)
return;

do
{
if(wfd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
if(wfd.cFileName[0] == '.')
continue;

TCHAR szFn[MAX_PATH];

lstrcpy(szFn, szF);

lstrcat(szFn,"\\");

lstrcat(szFn,wfd.cFileName);

cout<
func(szFn);
}

}while( FindNextFile(hFind,&wfd) );

}

void main()
{

TCHAR* sR[4] = {"C:","D:","E:","F:"};

for(int i=0; i<4; i++)
func( sR[i] );

cin.get();

}