谁有查找目录及子目录中所有文件的函数,将找到的文件放到TStrings。

ljhsoft 2002-04-05 10:12:23
我以前写了一个,使用替归的方法实现的,后来丢了手提电脑连函数也丢了。
TString * __fastcall GetFileFromDir(AnsiString strPathName)
{
//添加代码
}
...全文
66 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccnuxjg 2002-04-05
  • 打赏
  • 举报
回复
我上个月刚写的,送给你

void CNormalSearchDlg::OnOk()
{
// TODO: Add your control notification handler code here
int filenum = 0;
CString *filepath = 0;
filepath = new CString[1000];

FindTheExtFile( "D:\\temp", ".chm", filenum, filepath );

if( filepath!=NULL )
{
delete[]filepath;
filepath = NULL ;
}
}

//------------------------------------------------------------------------------------------------
// 函数名:FindTheExtFile
//
// function: search all the file in the Path that it's external name is Exname
// return: 所有的找到文件的完整路径--一个指针
// how to use: FindTheExtFile( "D:\\temp", ".chm", filenum, filepath );
// 作者: xiangjiangang
// Finish Date: 10:07 2002-3-29
//------------------------------------------------------------------------------------------------
BOOL CNormalSearchDlg::FindTheExtFile(const CString Path, const CString ExName, int &count, CString* OutPath)
{
CString tempPath[1000];
FindAllFile( Path, count, tempPath );
//在此过滤非扩展路径名的文件
int j = 0;
for( int i = 0; i < count; i ++ )
{
if( tempPath[i].Right( 4 ) == ExName )
{
OutPath[j] = tempPath[i];
j++;
}
}
count = j;

return TRUE;
}

//----------------------------------------------------------------------------------------
// 函数名:FindAllFile
//
// function: search all the file in the Path
// return: 所有的找到文件的完整路径--一个指针
// how to use: FindAllFile( Path, count, tempPath );
// 作者: xiangjiangang
// Finish Date: 10:07 2002-3-29
//----------------------------------------------------------------------------------------
BOOL CNormalSearchDlg::FindAllFile(const CString Path, int &count, CString *OutPath)
{
CFileFind tempFind;
char tempFileFind[200];

sprintf( tempFileFind, "%s\\*.*", Path );//先查找所有文件,这样不会遗漏子目录下面的文件
BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);

while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())//if the found file has the name "." or "..",是一真实路径
{
char foundFileName[200];
strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));//得到找到的文件的文件名或子路径
if(tempFind.IsDirectory())//如果是下层目录
{
char tempDir[200];
sprintf(tempDir,"%s\\%s",Path,foundFileName);
FindAllFile( tempDir, count, OutPath );//递归调用函数进行深度搜索
}
else
{
char tempFileName[200];
sprintf(tempFileName,"%s\\%s",Path,foundFileName);
OutPath[count] = tempFileName;//得到输出文件完整路径
count++;
}
}
}
tempFind.Close();

return TRUE;
}

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧