如题,上午我问过这个问题,得到一个答案:
DWORD dw = ::GetFileAttributes("C:\\test") ;if( dw & FILE_ATTRIBUTE_DIRECTORY )
{
AfxMessageBox("是目录") ;
}
else
{
AfxMessageBox("不是目录") ;
}但这种方法只能判断出 d;\temp 是目录, test.log不是目录。
现在我想判断 d:\temp\test.log 这个,我不想用截取字符串的方法。
有其他方法吗?
DWORD dw = ::GetFileAttributes("C:\\test") ;if( dw & FILE_ATTRIBUTE_DIRECTORY )
{
AfxMessageBox("是目录") ;
}
else
{
AfxMessageBox("不是目录") ;
}但这种方法只能判断出 d;\temp 是目录, test.log不是目录。
现在我想判断 d:\temp\test.log 这个,我不想用截取字符串的方法。
有其他方法吗?
{
CFileFind ff;
CString szDir = strDir;
if(szDir.Right(1) != "\\")
szDir += "\\";
szDir += "*.bmp";
BOOL res = ff.FindFile(szDir);
while(res)
{
res = ff.FindNextFile();
if(ff.IsDirectory() && !ff.IsDots())
{
//如果是一个子目录,用递归继续往深一层找
BrowseDir(ff.GetFilePath());
}
else if(!ff.IsDirectory() && !ff.IsDots())
{
//显示当前访问的文件
CStatic* p = (CStatic*)GetDlgItem(IDC_STATIC_FILE);
CString str;
str.Format("当前访问的文件:%s",ff.GetFilePath());
p->SetWindowText(str);
Sleep(500);
}
}
ff.Close();//关闭
}
给你看一找目录下为bmp的文件,会有启发的吧~~~
{
AfxMessageBox("是目录") ;
}
else
{
AfxMessageBox("不是目录") ;
}
用CFileFind也可以它有IsDirectory函数
参照 windindance(风舞轻扬·白首为功名) 解决问题.
BOOL res = ff.FindFile(csTmp);
while(res)
{
res = ff.FindNextFile();
if(ff.IsDirectory() && !ff.IsDots())
{
AfxMessageBox(csTemp + "是目录") ;
}
else
{
AfxMessageBox("不是目录") ;
}}
ff.Close();//关闭to : lixiaosan(小三)
GetFileAttributes的参数中含有路径就不能正确判断了,我不知道为什么。