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

使用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 directoryrecursively 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 searchcall 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;
}



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

 

转载于:https://www.cnblogs.com/shuilan0066/p/4032205.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值