打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
判断目录是否存在
VC判断路径是否存在
 
方法一:
 
 
CFileFind m_FileFind;
CString m_sFilePath = "D:\\Program Files\\Adobe\\Adobe Flash CS3";
if(!m_FileFind.FindFile(m_sFilePath))  //路径不存在则创建该路径
{
      CreateDirectory(m_sFilePath,NULL);
}
方法二:
CString   strFilePath;
strFilePath   =   "E:\\图像\\";
strFilePath   +=   m_ID;
if   (!SetCurrentDirectory(strFilePath))  
{
     CreateDirectory(strFilePath, NULL);
}
方法三:
FindFirstFile()/
#define _WIN32_WINNT 0x0400
#include "windows.h"
int
main(int argc, char *argv[])
{
  WIN32_FIND_DATA FindFileData;
  HANDLE hFind;
  printf ("Target file is %s.\n", argv[1]);
  hFind = FindFirstFile(argv[1], &FindFileData);
  if (hFind == INVALID_HANDLE_VALUE) {
    printf ("Invalid File Handle. Get Last Error reports %d\n", GetLastError ());
  } else {
    printf ("The first file found is %s\n", FindFileData.cFileName);
    FindClose(hFind);
  }
  return (0);
}
方法四:
FILE *fp = fopen(strPath, "r")
if(fp == NULL)
{
//没有同名文件
}
方法五:
 
  CString   strPath;  
  strPath   =   "c:\\abc.dat"  
  if(GetFileAttributes(strPath)   ==   0xFFFFFFFF)  
  {  
  AfxMessageBox("文件不存在");  
  return;  
  }  
。。。。。。。。。。
程序如下:  
  CString   filePath   =   "C:\\abc\\";  
  DWORD   dwAttr   =   GetFileAttributes(filePath);  
  if(dwAttr==-1||(dwAttr&FILE_ATTRIBUTE_DIRECTORY)==0)//目录不存在  
  {  
  if   (   !CreateDirectory(filePath,   NULL)   )  
  {  
  AfxMessageBox("不能创建目录");  
  return;  
  }  
  }  
方法六:
  WIN32_FIND_DATA   tFile;  
  memset(&tFile,   0,   sizeof(tFile));  
  CString   str   =   "d:\eeagadg\...";  
  if(FindFirstFile(str,   &tFile)   ==   INVALID_HANDLE_..)  
          不存在
 
方法七:
  int   _access(    
        const   char   *path,    
        int   mode    
  );  
。。。。。。。。
  #include   <io.h>  
  .....  
  char   szPathName[MAX_PATH]   =   "C:\\ABC";  
  if(_access(szPathName,0)   ==   0)  
        MessageBox(NULL,"该文件夹已经存在","提示",0)  
  else  
    CreateDirectory(szPathName,NULL);
——————————————————————————————————————
——————————————————————————————————————
我在MFC程序中 用的是方法一:
 CString file;
 CFileFind fileFind;
 file=_T("D:\\T1\\T2");
   if (!fileFind.FindFile(file))
   {
   CreateDirectory(file,NULL);
   }
因为用其他方法时,可能要加额外的头文件 所以选择了这一个
参考资料:
 
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/shuilan0066/archive/2009/10/26/4728298.aspx
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/shuilan0066/archive/2009/10/26/4728298.aspx
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/shuilan0066/archive/2009/10/26/4728298.aspx
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
[转载]VC中判断目录,文件是否存在,创建目录,求目录或
VC文件目录常见操作
判断是否合法的windows目录
ini文件读写
一个文件中读取数据并显示的程序
遍历文件夹并建成目录树 - VC知识库文章
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服