Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4466682
  • 博文数量: 356
  • 博客积分: 10458
  • 博客等级: 上将
  • 技术积分: 4734
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-24 14:59
文章分类

全部博文(356)

文章存档

2020年(17)

2019年(9)

2018年(26)

2017年(5)

2016年(11)

2015年(20)

2014年(2)

2013年(17)

2012年(15)

2011年(4)

2010年(7)

2009年(14)

2008年(209)

分类: C/C++

2008-03-25 17:41:47

发现有很多优化软件  在做删除 系统冗余文件时  会把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;
}

阅读(3622) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~