打开APP
userphoto
未登录

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

开通VIP
判断文件夹是否存在(多种方式)

1.BOOL PathFileExists(LPCTSTR pszPath);

    要包含的头文件

          #include <windows.h>
         #include <iostream.h>
        #include "Shlwapi.h"

2._access

    include  <io.h>
       #include  <stdio.h>
        #include  <stdlib.h>

      void main( void )
      {
           /* Check for existence */
           if( (_access( "ACCESS.C", 0 )) != -1 )
          {
                printf( "File ACCESS.C exists\n" );
              /* Check for write permission */
            if( (_access( "ACCESS.C", 2 )) != -1 )
         printf( "File ACCESS.C has write permission\n" );
       }
     }

3.bool dirExists(CString sPath)
{  
    //创建一个指定的全路径目录,失败就返回false  
    TCHAR* fullPath = _tfullpath (NULL, sPath, 0);  
    if (fullPath == NULL)     
          return false;   
    //通过设置fullPath为默认目录来检测是否存在
    Check if directory exists by trying to make it the default directory  
    TCHAR szCurrDir[_MAX_PATH];  
    _tgetcwd(szCurrDir, _MAX_PATH-1); //返回当前工作目录 
    long nStatus = _tchdir(fullPath); //改变当前工作目录 
    _tchdir(szCurrDir); //返回  
    free(fullPath);      
    if (nStatus == 0)     
          return true;  
    return false;
}
4.BOOL IsFileExists(LPCTSTR lpszFileName)
{
        WIN32_FIND_DATA wfd;
        BOOL bRet;
        HANDLE hFind;
        hFind = FindFirstFile(lpszFileName, &wfd);
        bRet = hFind != INVALID_HANDLE_VALUE;
        FindClose(hFind);
        return bRet;
}

5.SetCurrentDirectory(path)

    返回TRUE表示文件夹存在

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
使用FindFirstFile,FindNextFile遍历一个文件夹
判断目录是否存在的几种方法(转帖)
C#2010 在TreeView控件下显示路径下所有文件和文件夹
将pc中的文件夹从一个目录拷贝到另外的一个目录
VC判断文件目录是否存在的众多方法 - 含笑的日志 - 网易博客
MFC学习之判断文件是否存在的三种方法_mfc判断文件是否存在
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服