怎么获取文件夹下文件的数目? 怎么获取文件夹下文件的数目?,只能通过遍历吗?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int g_nCounter = 0;void ListFolder(CString sPath){ CFileFind ff; BOOL bFound; bFound = ff.FindFile(sPath + "\\*.*"); while(bFound) { bFound = ff.FindNextFile(); CString sFilePath = ff.GetFilePath(); if(ff.IsDirectory()) { if(!ff.IsDots()) ListFolder(sFilePath); } else { g_nCounter++; } } ff.Close();} 系统你一点右键属性就能看到有多少文件,很快的也是遍历做的吗?有没有什么API能直接得到阿 只有这一个办法 CFileFind,其实就是封装了API函数HANDLE FindFirstFile( LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData);和BOOL FindNextFile( HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData); while(bFound && g_nCounter>=500) 遍历CString file = m_strPath + m_strFileNameO + _T( "???") + m_strExtend; CFileFind finder; int nCount = 0; // file num // contain file name in format : psm21i???.dbf|psm21i???.dbf| CString result = _T(""); // get the file name in the variable "result" BOOL bExist = finder.FindFile( file ); if( !bExist ) return; while ( bExist ) { bExist = finder.FindNextFile(); CString strFileName = finder.GetFileName(); if( ParseFileName( strFileName ) ) { result += strFileName + "|"; nCount++; } } // fill in variable "aryListFileName" aryListFileName->SetSize( nCount ); CString strFileName; for( int i = 0; i < nCount; i++ ) { int nleft = result.FindOneOf( "|" ); strFileName = result.Left( nleft ); result = result.Right( result.GetLength() - nleft - 1 ); aryListFileName->SetAt( i, strFileName ); } VC中修改添加、修改word菜单,改变菜单事件 设置SO_DONTLINGER选项时,参数为TRUE和FALSE分别表示什么含义啊? 问一个比较高深的问题! 在VC下编译时出现的一个错误,以困扰数日,请各位帮帮忙!!! 能否在打开文件对话框上实现“一键全选”呢?在线等,谢谢 一个编译时令我费解的错误!请教各位! 借人气问个Ollydbg调试的问题~~高手赐教 多线程访问同一个函数的互斥性问题 关于猫和来电显示的问题 小妹妹又有问题了!求助大虾! 那位兄弟给个windows下WSAEventSelect的例子看看? 使用vector的一个异常
void ListFolder(CString sPath)
{
CFileFind ff;
BOOL bFound;
bFound = ff.FindFile(sPath + "\\*.*");
while(bFound)
{
bFound = ff.FindNextFile();
CString sFilePath = ff.GetFilePath(); if(ff.IsDirectory())
{
if(!ff.IsDots())
ListFolder(sFilePath);
}
else
{
g_nCounter++;
}
}
ff.Close();
}
有没有什么API能直接得到阿
HANDLE FindFirstFile(
LPCTSTR lpFileName,
LPWIN32_FIND_DATA lpFindFileData
);
和
BOOL FindNextFile(
HANDLE hFindFile,
LPWIN32_FIND_DATA lpFindFileData
);
CString file = m_strPath + m_strFileNameO + _T( "???") + m_strExtend;
CFileFind finder;
int nCount = 0; // file num // contain file name in format : psm21i???.dbf|psm21i???.dbf|
CString result = _T(""); // get the file name in the variable "result"
BOOL bExist = finder.FindFile( file ); if( !bExist )
return; while ( bExist )
{
bExist = finder.FindNextFile();
CString strFileName = finder.GetFileName();
if( ParseFileName( strFileName ) )
{
result += strFileName + "|";
nCount++;
}
} // fill in variable "aryListFileName"
aryListFileName->SetSize( nCount ); CString strFileName;
for( int i = 0; i < nCount; i++ )
{
int nleft = result.FindOneOf( "|" );
strFileName = result.Left( nleft ); result = result.Right( result.GetLength() - nleft - 1 ); aryListFileName->SetAt( i, strFileName );
}