如何判断目录是否有效?
解决方案 »
- 闲来无事,建立一个群,讨论面向对象思想,欢迎有见地的朋友来给我们普及一下 ----231537451
- 今天笔试题让我大感意外。。。
- 如何让EDIT_Control中EN_CHANGE事件响应延迟执行.
- 关于MFC消息映射中术语 “Windows”的疑问
- MSXML xmlHttp.这个能像msxml生成,解析msxml吗?同时对于http+xml的包,能进行解析吗?
- 请问com组件中怎么用多线程
- 无模式对话框问题
- 比较急,怎样再CString中输入换行符
- 轻松拿分了!!!
- enum { IDD = IDD_ABOUTBOX } 这句话什么作用?
- 请问用什么工具可以把EXE文件中的资源取出来???
- 怎样察看win2000下的*号密码
{
WIN32_FIND_DATA wfd; // 查找
HANDLE hFind=FindFirstFile(strDir,&wfd);
if (hFind==INVALID_HANDLE_VALUE)
return false; // 没有找到配备,目录肯定不存在
else {
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // 检查找到的结果是否目录
return true; // 是目录,目录存在
else
return false; // 是目录,目录不存在
FindClose(hFind);
}
}
return false;
void CListCtrlExtra::addFileFolder(LPCTSTR filename)
{
struct _stat buf;
int result = _tstat(filename, &buf );
if( result == 0 ) //if result !=0, then it failed altogether
{ // a directory?
if ((buf.st_mode & _S_IFDIR) == _S_IFDIR)
{ WIN32_FIND_DATA FindFileData;
HANDLE hFind;
CString dirpath = filename;
dirpath+="\\*"; hFind = FindFirstFile(dirpath, &FindFileData); if (hFind == INVALID_HANDLE_VALUE)
{ //printf ("Invalid File Handle. Get Last Error reports %d\n", GetLastError ());
}
else
{ //look into directory
do
{ if(FindFileData.cFileName[0]!='.')
{ dirpath = filename;
dirpath += "\\";
dirpath += FindFileData.cFileName;
//InsertItem(GetItemCount(), dirpath);
addFileFolder(dirpath); //recursively add directories, or just add the file
}
}
while(FindNextFile(hFind, &FindFileData));
FindClose(hFind);
} }
else //file not folder
{ if(!allowduplicates)
{ for(int i=0;i<GetItemCount();i++)
{ if(GetItemText(i,0).CompareNoCase(filename)==0)
{ return; //match found, do not add the file again
}
}
}
InsertItem(GetItemCount(), filename);
}
}
}
1、
CFileFind f;
if(f.FindFile("c:\\temp"))
AfxMessageBox("存在");
//Directory exist.
else
AfxMessageBox("不存在");
//Not exist.2、
if(_access("c:\\temp", 0) == 0){
AfxMessageBox("存在");
}
else{
AfxMessageBox("不存在");
}
CFileStatus rStatus;
if(!CFile::Open(目錄名,rStatus)){
//不存在.也可以用來判斷文件.
}
是否有效到底是甚麼意思?如果是判斷文件名是否正確的話.就是判斷文件名裡面不應該存在非法子符就可以了