各位帮忙!扫描所有硬盘,搜索某一类型的文件,扫描程序怎么写?有没有源码?感激不尽
解决方案 »
- 在类中使用静态成员变量句柄出现问题
- 背景窗口刷新不对,帮忙看看!
- 如何使菜单项变灰问题
- vc对话框
- 游戏外挂是怎么实现在游戏戏窗口中调出自己的窗口,并且不会将游戏窗口隐到后台!
- 用SHFileOperation如何复制多个文件?
- 用waveInStart将声音录入内存后,应该怎样转换成wav格式保存到硬盘上?
- 从分割视得到主框架的指针?
- ?????谁能告诉我~~~哦~~~谁能告诉我????????
- 视频采集的回调函数,很急,帮帮忙
- 这是什么错误:missing storage-class or type specifiers ?
- 左边带有小图标的菜单的文字信息怎样得到?用GetMenuString函数好象不行了?
FindFirstFile()、FindNextFile()、FindClose()(MFC)
This small program recurses every directory on the C:\ drive and prints the name of the directory.#include <afx.h>
#include <iostream>using namespace std;void Recurse(LPCTSTR pstr)
{
CFileFind finder; // build a string with wildcards
CString strWildcard(pstr);
strWildcard += _T("\\*.*"); // 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())
{
CString str = finder.GetFilePath();
cout << (LPCTSTR) str << endl;
Recurse(str);
}
} finder.Close();
}void main()
{
if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0)
cout << "panic!" << endl;
else
Recurse(_T("C:"));
}
GetFile(CString sDir)
{
CFileFine ff;
BOOL bContinue = ff.FindFile(sDir+"\\*.*");
//把*.*改成别的扩展名,就实现了文件的过滤 while(bContinue)
{
bContinue = ff.FindNextFile();
if(ff.IsDots())//这是 . 和 ..
continue;
if(ff.IsDirectory())//这是目录,遍历这个目录
GetFile(ff.GetFilePath());
else//这是文件,可以往数据库里存了
{
CString sFileName = ff.GetFilePath();
} }
ff.Close();
}然后调用,比如GetFile("c:")就可以了可以参考帖子
http://expert.csdn.net/Expert/topic/1975/1975673.xml?temp=.1268122