CFileFind类成员函数IsDots, IsDirectory

别说谁变了你拦得住时间么 提交于 2020-01-20 16:51:14

IsDots检测.和.两个目录(缺省目录)。
.代表当前目录;
…代表上一层目录;
eg:程序当前目录: c:\windows\temp,
. = c:\windows\temp;
… = c:\windows;

IsDirectory表明这是一个目录

遍历目录下文件时,需要过滤掉.和…这两个缺省目录。所以由CFileFind对象引用IsDots的意思是:这是一个目录并且不是这个目录本身或者上层目录。

void Recurse(LPCTSTR pstr) // 设置一个目录,比如:"c:\\windows"
{
   CFileFind finder;
 
   CString sPath(pstr);
   sPath += _T("\\*.*");
 
   BOOL bWorking = finder.FindFile(sPath);
 
   while (bWorking)
   {
      bWorking = finder.FindNextFile();
 
      // 跳过 . 和 .. ; 否则会陷入无限循环中!!!
      if (finder.IsDots())
         continue;
 
      // 如果是目录,进入搜索 (递归ing)!!!
      if (finder.IsDirectory())
      {
         CString str = finder.GetFilePath();
         TRACE(_T("%s\n"), (LPCTSTR)str);
         Recurse(str);
      }
      else
      {
          //不是目录,作点啥呢? <=== 按需添加你的代码如下!!
          ;
      }
   }
 
   finder.Close();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!