如何得到一个文件夹下包含子目录与文件的数量和
解决方案 »
- memcpy?需includ ?
- 最近学VC好郁闷,迫切高手来帮我开窍呀.帮帮忙了.
- 请教:当我 insert-->resource-->选中 -->Bitmap-->import 加载图片时出现下面的错误,谢谢!
- 急!急!!急!!!高手请留步!新建类中为什麽不能添加响应菜单按钮的函数?!!
- 如何解析DNS服务器的地址??
- 如何封装ADO数据库编程?
- 大虾们快来帮忙
- 北京那个地方在买《windows程序设计》的。能打几折?
- 怎么才能编一个软件,使它能像那些短信发送网站一样,只要能上网就能向手机发短信?(我不想在程序中调用那些网站的CGI)我想自己写,怎
- 大专生有没有做软件开发的能力?
- ☆☆☆☆求救!!求救!!求救!!☆☆☆☆
- 在ToolBar上加上两个箭头按钮,点击按钮,可以使ToolBar左右移动
这个我也会啊,只是有点慢啊,6万个文件的遍历需要1分多钟吧,有没有更快的啊?
void CDeleteRubbishFileDlg::GetFolderFilesCount(char *pPathName)
{
CFileFind finder;
char pathName[LEN],childPath[LEN];
BOOL flag;
CString childDir;
memset(pathName,0x00,LEN);
flag=finder.FindFile();
while(flag)
{
flag=finder.FindNextFile();
if(finder.IsDots())
{
continue;
}
memset(childPath,0x00,LEN);
childDir=finder.GetFileName();
lAllNumber++;
if(finder.IsDirectory())
{
CString temp = finder.GetFilePath();
char *pTemp;
pTemp = (LPSTR)(LPCTSTR)temp;
::_chdir(pTemp);
GetFolderFilesCount(childPath);//递归调用
}
else
{
}
}
}
CStringArray m_arrType;
m_arrType.RemoveAll();
m_arrType.Add("*.dpj");//可以添加不同的搜索后缀
//如果sPath为目录,就继续检查他的是否仍然有下一级子目录;
void CDlgPrjManager::SearchDirectory(LPCTSTR Path)
{
CString sPath=Path;
if(sPath.Right(1)!='\\')
{
sPath += "\\";
}
FindFiles(sPath);
sPath+="*.*";
CFileFind ff;
BOOL bWorking = ff.FindFile(sPath);
if (!bWorking) return;
while (bWorking)
{
bWorking = ff.FindNextFile();
if (ff.IsDots())
continue;
if (ff.IsDirectory()){
CString str=ff.GetFilePath();
str+='\\';
SearchDirectory(str);
}
}
}//如果sPath为文件,就自动搜索是否符合后缀要求,符合就添加到列表中;
void CDlgPrjManager::FindFiles(CString sPath)
{
CString sDestPath="";
CString sExt;//记录后缀
int nExtLen = 0;
CString sFileName = "";
int size=m_arrType.GetSize();
for(int i=0;i<size;i++){
CString TmpPath;
TmpPath=sPath;
sExt = m_arrType[i];//加上对文件类型的判断
TmpPath+=sExt;
sExt = sExt.Mid(1);//去掉“*”.
nExtLen = sExt.GetLength();
CFileFind ff;
BOOL bWorking = ff.FindFile(TmpPath);
if (!bWorking && i<size ) continue;
else if(!bWorking && i>=size) return;
while (bWorking)
{
bWorking = ff.FindNextFile();
if (ff.IsDots())
{
continue;
}
if (ff.IsDirectory()){ //this is impossible.
continue;
}
if (!ff.IsDirectory()) //file
{
sFileName = ff.GetFilePath();
//AddNewItemToList(sFileName, false);
}
}
}
}
int m_nFileNum;在构造函数中初始化
m_nDirNum = 0;
m_nFileNum = 0;void FindMyFile(CString path)
{
BOOL bFind, bFindSuffix;
CFileFind tempFind, tempFind1;
_chdir(path);
bFind = tempFind.FindFile("*.*");
while(bFind)
{
bFind = tempFind.FindNextFile();
CString str = tempFind.GetFilePath();
if(tempFind.IsDirectory())
{
if (!tempFind.IsDots() )
{
m_nDirNum++;
CString temppath;
temppath = tempFind.GetFilePath();
FindMyFile(temppath);
}
}
}
_chdir(path);
bFindSuffix = tempFind1.FindFile("*.*");
while(bFindSuffix)
{
bFindSuffix = tempFind1.FindNextFile();
CString tempfile;
if( !tempFind1.IsDirectory() && !tempFind1.IsDots())
{
tempfile = tempFind1.GetFilePath();
m_strArrFilename.Add(tempfile);
m_nFileNum++;
}
}
tempFind.Close();
tempFind1.Close();
}
没得快了
Windows自己算6W多个也要好长时间呢吧