码迷,mamicode.com
首页 > 编程语言 > 详细

C/C++判断文件/文件夹是否存在 转

时间:2016-12-04 16:17:55      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:tor   .com   har   file   rmi   mode   http   his   blog   

一、判断文件夹是否存在:
     1.用CreateDirectory(".//FileManege",NULL);如果文件夹FileManege不存在,则创建。
     2.或者if(_access(".//FileManege",0)==-1),表示FileManege不存在。
     3.或者BOOL PathIsDirectory(LPCTSTR pszPath);

二、判断文件是否存在:
     1.用if((file=fopen(".//FileManege//F//F.dat","rb"))==NULL)
         file=fopen(".//FileManege//F//F.dat","ab+"); // 先判断有无文件,没的话新建一个
     2.用if(_access(".//FileManege//F//F.dat",0)==-1),表示文件不存在。


       函数int _access( const char *path, int mode );可以判断文件或者文件夹的mode属性
       mode=00;//Existence only
       mode=02;//Write permission
       mode=04;//Read permission
       mode=06;//Read and write permission
       需要包含头文件<io.h>。

 

 

转自:http://luzongping1986.blog.163.com/blog/static/788129152009379452504/

C/C++判断文件/文件夹是否存在 转

标签:tor   .com   har   file   rmi   mode   http   his   blog   

原文地址:http://www.cnblogs.com/wolfplan/p/6130838.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!