如何确定一个文件目录是否存在? 在创建一个目录之前要确认该目录是否存在,如果不存在,在用户确认后创建该目录。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CFileFind FileFind; if(FileFind.FindFile(m_strTempFile)) { ; } else { while(ilength !=-1) { CString strDirectory =m_strTempFile.Left(ilength); if(!FileFind.FindFile(strDirectory,0)) if(!CreateDirectory(strDirectory,NULL)) { ::MessageBeep(MB_ICONHAND); MessageBox(IMAGE_LOADER_CREATEDIRETORY_ERR, NULL, MB_OK + MB_ICONSTOP + MB_SYSTEMMODAL); } ilength = m_strTempFile.Find("\\",ilength+1); } } int _access( const char *path, int mode );// mode Value Checks File For // 00: Existence only // 02: Write permission // 04: Read permission // 06: Read and write permission // Example:if (_access("PathName", 0 )) != -1) { // ...} 用不着File Find这么麻烦正如 kimryo(一切皆有可能)所说的,用PathFileExists就行了。 慢了一步,呵呵,就是PathFileExists函数最方便了。 I use thisDWORD dwAttr = GetFileAttributes( strRoot ); if ( dwAttr == -1 ) { //如果用户指定的路径不存在则要生成一个_________________________________________________PathFileExists_________________________________________________// Example:if (_access("PathName", 0 )) != -1) { // ...}_________________________________________________FileFind.FindFile(m_strTempFile_________________________________________________还有没有其它方法 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("不存在"); } Windows如何生成系统共用的对象 自绘控件 自己写了个小工具,安装后运行第二次就报错了 无法定位程序输入点 关于视口和窗口! 用atl写的ActiveX在IE中的使用问题 一个简单又头痛的MFC问题 用的是西门子2118和串口调试程序,如何发送AT命令?(在线等!!) 从磁盘上读取图像文件一直显示不出来,急!!! 急问VC如何实现控制条码打印机???在线等大家帮忙 ●●CString型的"A"怎样转换为char型的'A'?●● 线程问题?
if(FileFind.FindFile(m_strTempFile))
{
;
}
else
{
while(ilength !=-1) {
CString strDirectory =m_strTempFile.Left(ilength);
if(!FileFind.FindFile(strDirectory,0))
if(!CreateDirectory(strDirectory,NULL))
{
::MessageBeep(MB_ICONHAND);
MessageBox(IMAGE_LOADER_CREATEDIRETORY_ERR, NULL, MB_OK + MB_ICONSTOP + MB_SYSTEMMODAL);
}
ilength = m_strTempFile.Find("\\",ilength+1);
}
}
// mode Value Checks File For
// 00: Existence only
// 02: Write permission
// 04: Read permission
// 06: Read and write permission // Example:
if (_access("PathName", 0 )) != -1) {
// ...
}
正如 kimryo(一切皆有可能)所说的,用PathFileExists就行了。
DWORD dwAttr = GetFileAttributes( strRoot );
if ( dwAttr == -1 )
{
//如果用户指定的路径不存在则要生成一个
_________________________________________________
PathFileExists_________________________________________________
// Example:
if (_access("PathName", 0 )) != -1) {
// ...
}_________________________________________________
FileFind.FindFile(m_strTempFile
_________________________________________________
还有没有其它方法
CFileFind f;
if(f.FindFile("c:\\temp"))
AfxMessageBox("存在");
//Directory exist.
else
AfxMessageBox("不存在");
//Not exist.2、
if(_access("c:\\temp", 0) == 0){
AfxMessageBox("存在");
}
else{
AfxMessageBox("不存在");
}