码迷,mamicode.com
首页 > 其他好文 > 详细

查找指定目录下的文件?.xml

时间:2014-10-17 23:20:31      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   io   os   ar   使用   for   sp   

使用CFindFile类,?此类主要是用来查找文件的,首先调用?FindFile()?函数?,来开始查找过程,然后调用FindNextFile来得到后续的文件信息等。

注意:?此类在vs控制台下不能编译成功,只能在MFC运行才可以

?
?
?
MSDN中的解释为:
?
Call?this?member?function?to?open?a?file?search.
virtual?BOOL?FindFile(
???LPCTSTR?pstrName?=?NULL,
???DWORD?dwUnused?=?0?
);

例子:

?
Example?
This?small?program?recurses?every?directory?on?the?C:/?drive?and?prints?the?name?of?the?directory.
#include?<afxwin.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();
}
int?main()
{
???if?(!AfxWinInit(GetModuleHandle(NULL),?NULL,?GetCommandLine(),?0))
??????cout?<<?"panic!"?<<?endl;
???else
??????Recurse(_T("C:"));
}
?
?

其它网络资料:

现有很多优化软件?在做删除?系统冗余文件时?会把LJ文件的名字?显示在一个列表中?供用户删除.

这就用到了遍历文件夹下所有文件的技术了.?于是就像自己写一个出来.?但以前都没接触过?所以查了下MSDN?输入?findfile尽然有这样的函数?暗喜还有代码实例?稍微改了下一点点的代码?如果再修改下?可以做成删除特定的一组文件也可以自己做一个删除系统LJ的软件?有待大家去发挥想像力了

对此函数说明如下:

Call?this?member?function?to?open?a?file?search.
virtual?BOOL?FindFile(
LPCTSTR?pstrName?=?NULL,
DWORD?dwUnused?=?0
);
After?calling?FindFile?to?begin?the?file?search,?call?FindNextFile?to?retrieve?subsequent?files.?You?must?call?FindNextFile?at?least?once?before?calling?any?of?the?following?attribute?member?functions:

说的是此函数用于开始一个文件查找,当查找到之后,可以调用FindNextFile连续得查找一组文件

?

#include?<afxwin.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;
???????????CString?sFileName?=?finder.GetFileName();
??????????cout?<<?(LPCTSTR)sFileName?<<?endl;//输出查找文件夹下的所有文件名
??}
???finder.Close();
}
int?main()
{
??if?(!AfxWinInit(GetModuleHandle(NULL),?NULL,?GetCommandLine(),?0))//初始化MFC
??????cout?<<?"panic!"?<<?endl;
??else
???????Recurse(_T("C:"));
????????return?0;
}

本文使用?书画小说软件?发布,内容与软件无关,书画小说软件?更惬意的读、更舒心的写、更轻松的发布。

查找指定目录下的文件?.xml

标签:style   http   color   io   os   ar   使用   for   sp   

原文地址:http://www.cnblogs.com/shuilan0066/p/4032205.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!