在Edit1中给出"cpp"等后缀名,应该如何样在系统中搜索出所有的cpp文件,并显示到ListBox1中呢
发布时间:2011-06-28 13:31:40 文章来源:www.iduyao.cn 采编人员:星星草
在Edit1中给出"*.cpp"等后缀名,应该怎么样在系统中搜索出所有的cpp文件,并显示到ListBox1中呢?
在Edit1中给出 "*.cpp "等后缀名,应该怎么样在系统中搜索出所有的cpp文件,并显示到ListBox1中呢? 请高手指点迷津!!!
------解决方案--------------------
struct ffblk ffblk;
int done;
done = findfirst( "*.cpp ",&ffblk,0);
while (!done)
{
Memo2-> Lines-> Add(AnsiString(ffblk.ff_name));
done = findnext(&ffblk);
}
done = findfirst( "*.h ",&ffblk,0);
while (!done)
{
Memo2-> Lines-> Add(AnsiString(ffblk.ff_name));
done = findnext(&ffblk);
}
int i, j;
j = Memo2-> Lines-> Count;
if (j == 0)
{
MessageBox(Handle, "该目录中没有C++源文件 ", "C++源文件信息提取 ",MB_OK | MB_ICONHAND);
return;
}
------解决方案--------------------
把_FindFileProc改写一下,支持通配符,完整代码:
bool g_bStopFlag;
//---------------------------------------
// 文件搜索函数(递归)
void _FindFileProc(String strFindFile, String strDir, TStrings *pList);
// 显示信息
void _ShowProcess(String strMsg);
// 用户调用的查找文件主函数
void CrnFindFile(String strFindFile, TStrings *pList);
//---------------------------------------
void _FindFileProc(String strFindFile, String strDir,
TStrings *pList)
{
WIN32_FIND_DATA wfd;
if(strDir.LastDelimiter( "\\ ") != strDir.Length())
strDir += "\\ ";
String strFile( " ");
HANDLE hFind;
// 查找该目录下的文件,支持通配符
hFind = FindFirstFile((strDir + strFindFile).c_str(), &wfd);
if(INVALID_HANDLE_VALUE != hFind)
{
do
{
Application-> ProcessMessages();
if(g_bStopFlag)
break;
strFile = String(wfd.cFileName);
_ShowProcess(strDir + strFile);
if(strFile == ". " || strFile == ".. ")
continue;
pList-> Add(strDir + String(wfd.cFileName));
}while(FindNextFile(hFind, &wfd));
}
FindClose(hFind);
// 查找子目录
hFind = FindFirstFile((strDir + "*.* ").c_str(), &wfd);
if(INVALID_HANDLE_VALUE != hFind)
{
do
{
Application-> ProcessMessages();
if(g_bStopFlag)
break;
strFile = String(wfd.cFileName);
if(strFile == ". " || strFile == ".. ")
continue;
// 如果是子目录就进入子目录搜索
if((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
== FILE_ATTRIBUTE_DIRECTORY)
{
_ShowProcess(strDir + strFile);
_FindFileProc(strFindFile, strDir + strFile + "\\ ", pList);
}
}while(FindNextFile(hFind, &wfd));
}
FindClose(hFind);
}
//---------------------------------------
void _ShowProcess(String strMsg)
{
Form1-> Caption = strMsg;
}
//---------------------------------------
void CrnFindFile(String strFindFile, TStrings *pList)
{
char szDrvBuf[100]; // 用于存放各盘的逻辑盘符的缓冲区
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
C#项目中如何更改项目保存的文件夹名?
求解。。
------解决方案--------------------
好像需要重构吧,同样求高人解答。
------...
-
C#中让TextBox只能输入数字的问题
我用的如下的代码:
static private Regex r = new Regex("^[0-9]{1,}$ ");
...
-
带数据库的程序打包注意什么?
打的包出错:Error:System.InvalidOperationException: ExecuteReader 要求已打开且可用的连接。连接的...
-
想学习一下网络程序开发 请给推荐几本书
学习基于http协议的程序开发 比如获取网页 分析网页 模拟网页操作 下载上传文档等知识 ...
-
qq的安装包是用什么工具?
想用.net制作一个想qq一样比较漂亮的安装包。有例子最好
------解决方案--------------------
新建->安...
-
C# 写的windows服务 调用 C++ dll 的问题
我封装了一个dll
用一个普通的winform程序 调用的时候没 问题。
但是放在C#写的服务程...
-
在VS2005中怎么调出 解决方案 那个图标?(图示)求解释~~~
这是我用的VS
这是我在教学视频上看到的VS
------解决方案------------...
-
寻友
有人在自学c#编程吗,可以互相认识一下,以后共同探讨学习中的问题……
------解决方案--------------------
朋友多了,路好走~
...
-
急!急!急!C#代码
怎样将数据库中的数据动态加载到Treeview控件中
------解决方案--------------------
C# code
void CreateTree(T...
-
救急??????????????????
哪位高手帮我一下,在C#中怎么写关于鼠标和键盘监听事件,我的程序就差监听鼠标和键盘是否动,然后定时关机这个功能了,请高手指点,...