各位帮忙!扫描所有硬盘,搜索某一类型的文件,扫描程序怎么写?有没有源码?感激不尽
解决方案 »
- 求助关于listbox控件的问题
- 如此用 this 清空结构体 可以吗?
- fopen的问题
- 用PostMessage为什么收不到消息?
- 我想用VC6实现拷贝问题,下面代码通不过,谁能为我改一下
- 怎么把一个CXXXView/CXXXDoc画到一个Dialog里去?
- 用过intel c++编译器的高手请进!
- 在vc中用sql语句建立一个表,能保存超过1000个汉字的列用什么类型?
- 如何用COM接口来提取HTML文件中的数据
- 面事题:操作系统是由什么组成的??
- 这是什么错误: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