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();
}