程序是想得到一个文件夹下bmp图像的数量,然后对每个bmp图像进行处理,想做一个进度条显示下处理文件的进度。
在使用CFileFind 的时候,为什么我第一个while中GetFileName没有任何问题,在第二个while中使用GetFileName就程序异常终止了。而且即使不是pszDplName文件路径也会程序异常终止。各位大虾请帮帮忙。谢谢了!~~ CProgressCtrl progress_m;
progress_m.Create(PBS_SMOOTH,CRect(10,10,500,30), FromHandle(m_hWnd), 1);
int numoffiles=0;
strcat(pszDplName,"\\*.bmp"); CFileFind finder;
BOOL bWorking = finder.FindFile(pszDplName);
while (bWorking)
{
numoffiles++;
bWorking = finder.FindNextFile();
//这里已经得到文件夹下的文件的数量了
finder.GetFileName();
} progress_m.SetRange(0,numoffiles);
numoffiles=0; bWorking = finder.FindFile(pszDplName);
while (bWorking)
{
MessageBox("dddd");
finder1.GetFileName();
bWorking = finder1.FindNextFile();///////每次程序运行到这里的时候就会出错!!!!!!!!!!~
progress_m.SetPos(numoffiles);
numoffiles++;
}
在使用CFileFind 的时候,为什么我第一个while中GetFileName没有任何问题,在第二个while中使用GetFileName就程序异常终止了。而且即使不是pszDplName文件路径也会程序异常终止。各位大虾请帮帮忙。谢谢了!~~ CProgressCtrl progress_m;
progress_m.Create(PBS_SMOOTH,CRect(10,10,500,30), FromHandle(m_hWnd), 1);
int numoffiles=0;
strcat(pszDplName,"\\*.bmp"); CFileFind finder;
BOOL bWorking = finder.FindFile(pszDplName);
while (bWorking)
{
numoffiles++;
bWorking = finder.FindNextFile();
//这里已经得到文件夹下的文件的数量了
finder.GetFileName();
} progress_m.SetRange(0,numoffiles);
numoffiles=0; bWorking = finder.FindFile(pszDplName);
while (bWorking)
{
MessageBox("dddd");
finder1.GetFileName();
bWorking = finder1.FindNextFile();///////每次程序运行到这里的时候就会出错!!!!!!!!!!~
progress_m.SetPos(numoffiles);
numoffiles++;
}
bWorking = finder1.FindNextFile();///////每次程序运行到这里的时候就会出错!!!!!!!!!!~
finder1 没定义,编译能通过吗?
应该是
finder.GetFileName();////////////每次程序运行到这里的时候就会出错!~
bWorking = finder.FindNextFile();
GetFileName
GetFileTitle
GetFilePath
GetFileURL
GetLastAccessTime
GetLastWriteTime
GetLength
GetRoot finder.GetFileName();
bWorking = finder1.FindNextFile();///////每次程序运行到这里的时候就会出错!!!!!!!!!!~
=============
bWorking = finder1.FindNextFile();///////每次程序运行到这里的时候就会出错!!!!!!!!!!~
finder.GetFileName();
finder.GetFileName();
这两句调整一下
给你一个MSDN上的例子:
CFileFind finder;
static const TCHAR szFileToFind[] = _T("C:\\WINDOWS\\SYSTEM.INI");BOOL bResult = finder.FindFile(szFileToFind);if (bResult)
{
finder.FindNextFile(); cout << "Root of " << szFileToFind;
cout << " is " << (LPCTSTR) finder.GetRoot();
cout << endl; cout << "Title of " << szFileToFind;
cout << " is " << (LPCTSTR) finder.GetFileTitle();
cout << endl; cout << "Path of " << szFileToFind;
cout << " is " << (LPCTSTR) finder.GetFilePath();
cout << endl; cout << "URL of " << szFileToFind;
cout << " is " << (LPCTSTR) finder.GetFileURL();
cout << endl; cout << "Name of " << szFileToFind;
cout << " is " << (LPCTSTR) finder.GetFileName();
cout << endl; finder.Close();
}
else
cout << "You have no " << szFileToFind << " file." << endl;
Output
Assumes that the file C:\WINDOWS\SYSTEM.INI exists:
Root of C:\WINDOWS\SYSTEM.INI is C:\WINDOWS
Title of C:\WINDOWS\SYSTEM.INI is SYSTEM
Path of C:\WINDOWS\SYSTEM.INI is C:\WINDOWS\SYSTEM.INI
URL of C:\WINDOWS\SYSTEM.INI is file://C:\WINDOWS\SYSTEM.INI
Name of C:\WINDOWS\SYSTEM.INI is SYSTEM.INI
BOOL CWddrmOper::FolderOperation(CString FolderPath,BOOL bRecover)
{
m_iAppLen=m_strAppPath.GetLength();//the length of app path CString strDir=m_strAppPath+FolderPath;//copy folder
if(strDir.Right(1) != "\\")
strDir += "\\";
strDir+="*.*";
CFileFind finder;
BOOL bWorking=finder.FindFile(strDir);//Error 应该是目标文件夹 it should be goal file
/** add by zhanglei 070404 START*/
if (!bRecover)
{
if(DirectoryExist(strDir))
{
return TRUE;
}
}
DeleteFolderInWDdrm(FolderPath);
/** add by zhanglei 070404 END*/
while (bWorking)
{
bWorking=finder.FindNextFile();
//child directory exist
if (finder.IsDirectory()&&!finder.IsDots())
{
CString strPath=finder.GetFilePath();
int len=strPath.GetLength();
CString strFolderNm;
strFolderNm=strPath.Right(len-m_iAppLen);//get the folder name
//call back
FolderOperation(strFolderNm,TRUE);
}
//child directory is not exist
else if(!finder.IsDirectory() && !finder.IsDots())
{
CString strPath;
strPath = finder.GetFilePath();
CString strTitle=finder.GetFileTitle(); int len=strPath.GetLength();
CString strFolderNm;
int n=strPath.ReverseFind('\\');
strFolderNm=strPath.Mid(m_iAppLen,n-m_iAppLen);//get the folder name
//copy file to assign folder
if(!FileOperation(strPath,strFderNm))
{
finder.Close();
return FALSE;
}
}
}
finder.Close();
return TRUE;
}