如何搜索本地文件 请大大告诉下

york528 2008-01-17 05:16:16
我想做一个搜索文件名的小软件
用FindFile 和 FindnextFile 只能找到文件夹的名字
请问找文件 怎么找啊

有大大会的请留下qq
或者e-mail
我会联系你们
非常需要这方面知识
...全文
117 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
york528 2008-01-19
  • 打赏
  • 举报
回复
问题解决 谢谢各位 用递归解决硬盘遍历问题了 哈哈
cclutpk 2008-01-18
  • 打赏
  • 举报
回复
1、3楼正解
york528 2008-01-18
  • 打赏
  • 举报
回复
谢谢各位大大们 我回去看看行不行 家里缓阻大 人家不给办网啊 郁闷 还有 我是新手 能给分把 怎么搞啊
abzhang2 2008-01-17
  • 打赏
  • 举报
回复
void FindFileMy(CString strPath)
{
CFileFind finder;
CTime tmcreate;
int ncol;
CString strTime;
// build a string with wildcards
CString strWildcard(strPath);
strWildcard += _T("\\*.txt");

// start working for files
BOOL bWorking = finder.FindFile(strWildcard);

while (bWorking)
{
bWorking = finder.FindNextFile();

// skip . and .. files; otherwise, we'd
// recur infinitely!

if (finder.IsDots())
continue;

// if it's a directory, recursively search it

if (!finder.IsDirectory())
{ //file
//CString str2 = finder.GetFilePath();
CString str2 = finder.GetFileName(); //找到文件了,是文件。 你可以进行处理,

}
else
{ //directory
CString str3 = finder.GetFilePath();
//FindFileMy(str3); //不用在更下一级别中去查找文件夹,如果想在下一级别中查找,请要这句 }
}

finder.Close();
}
cnzdgs 2008-01-17
  • 打赏
  • 举报
回复
FindFirstFile("*.*", &wfd);
注意要排除.和..两个目录
youyifang 2008-01-17
  • 打赏
  • 举报
回复

WIN32_FIND_DATA file_info;
char file_name[1024] = "";
HANDLE handle;
char *route = (char*)malloc(strlen(dirName) + 5);
char *pathname // 查找目录,
sprintf(route, "%s\\*.*", pathname);
handle = FindFirstFile(route, &file_info);
free(route);
if(INVALID_HANDLE_VALUE != handle)
{ //
do{
char *tempname = (char *)malloc(260);
sprintf(tempname, file_info.cFileName); //文件名字
//处理该文件
tempname = NULL;
}while( FindNextFile(handle, &file_info) );

这样你就可以找到所有包含在目录路经下的文件,在去匹配看是不是你指定的文件就可以了。
oldn123 2008-01-17
  • 打赏
  • 举报
回复
The following code will enumerate all the files in the current directory, printing the name of each file:

CFileFind finder;
BOOL bWorking = finder.FindFile("*.*");
while (bWorking)
{
bWorking = finder.FindNextFile();
cout << (LPCTSTR) finder.GetFileName() << endl;
}
  • 打赏
  • 举报
回复
那个api是可以找到文件的
youyifang 2008-01-17
  • 打赏
  • 举报
回复
后面需要加上*.*来搜索,这样才可以找到文件。

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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