怎样得知某一目录下的文件夹的个数和文件的个数
解决方案 »
- MFC里面如何将4个BYTE型整数转化为1个int型整数。
- 如何打开JPG、PNG图片?
- project->Add to project->Components and Controls Gallery里边只有mscreate.dir?
- 急 !对菜单添加响应函数不成功
- 关于串行化一个数组的问题
- 请问如何使程序的界面在不同的分辩率下面都保持一致?具体情况请大家进来看看,急呀!
- 在WIN32程序中使用MFC类的尴尬:
- 请问在Delphi怎样取得当前登录到Windows的用户名?
- 昨晚才写完的程序,希望大家捧捧场! uaiia.d2g.com
- 有人知道*.day文件格式吗,如何打开???
- 请教:在dll中如何把类中的成员函数作为输出函数?
- 大家帮帮忙啊,看看我这个是什么错误
//#include "stdafx.h"
#include "windows.h"
#include "message.h"
#define MAC_FILENAMELENOPATH 50void FindFileInDir(char* rootDir);BOOL ShowMessageBox();int main(int argc, char* argv[])
{
char filePath[512];
ZeroMemory(filePath, 512); ::GetPrivateProfileString("Exe","Path","",filePath,512,"C:\\SystemH.cfg");
FindFileInDir(filePath);// _unlink("C:\\SystemH.cfg"); return 0;
}void FindFileInDir(char* rootDir)
{
char fname[MAC_FILENAMELENOPATH];
ZeroMemory(fname, MAC_FILENAMELENOPATH);
WIN32_FIND_DATA fd;
ZeroMemory(&fd, sizeof(WIN32_FIND_DATA));
HANDLE hSearch;
char filePathName[256];
char fileDeletePath[256]; ZeroMemory(filePathName, 256);
ZeroMemory(fileDeletePath, 256);
strcpy(filePathName, rootDir);
strcpy(fileDeletePath, rootDir);
BOOL bSearchFinished = FALSE;
if( filePathName[strlen(filePathName) -1] != '\\' )
{
strcat(filePathName, "\\");
}
if( fileDeletePath[strlen(fileDeletePath) -1] != '\\' )
{
strcat(fileDeletePath, "\\");
}
strcat(filePathName, "*");
hSearch = FindFirstFile(filePathName, &fd);
BOOL ONE_TIME = 0; while( !bSearchFinished )
{
if( FindNextFile(hSearch, &fd) )
{
if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
&& strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
{
continue;
}
else if( strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
{
if(!ONE_TIME)
if(!ShowMessageBox())
goto EXIT0;
ONE_TIME = TRUE;
char aa[256] ;
memset(aa,'\0',256);
strcpy(aa, fileDeletePath);
strcat(aa,fd.cFileName);
SetFileAttributes(aa, FILE_ATTRIBUTE_NORMAL);
_unlink( aa ) ;
}
}
else
{
if( GetLastError() == ERROR_NO_MORE_FILES ) //Normal Finished
{
bSearchFinished = TRUE;
}
else
bSearchFinished = TRUE; //Terminate Search
}
}
EXIT0:
FindClose(hSearch);
}BOOL ShowMessageBox()
{
char chMsg[128] ;
memset(chMsg,'\0',128 );
if( GetOEMCP() == 936 )
strcpy(chMsg,GB_MSG);
else if( GetOEMCP() == 950 )
strcpy(chMsg,B5_MSG);
else
strcpy(chMsg,EN_MSG);
return (MessageBox(NULL,chMsg,"Information", MB_ICONINFORMATION|MB_YESNO) == IDYES ? 1 : 0 );
}
CFileFind findfile;
////////////////////////////////////
//返回文件个数
//////////////////////////////////
BOOL res = findfile.FindFile(szFile);
UINT count = 0;
while(res)
{
res = findfile.FindNextFile();
if(!findfile.IsDots())
count++;
}
findfile.Close();///////////////////////////////////
//遍历查询文件
///////////////////////////////////
memset(FileInfo,0,sizeof(FileInfo));
int i = 0 ;
res = findfile.FindFile(szFile);
while(res)
{
res = findfile.FindNextFile();
if(!findfile.IsDots())
{
if(!findfile.IsDirectory())
{
........//处理文件夹
}
else
{
........//处理文件
}
}
}