阿彪的Blog

能力在于平日里积累

原创 在VC里如何检查一个文件是否存在收藏

新一篇: 如何使用TinyXML来解析xml文档: | 旧一篇: 佛学来理解人生的道理

有一个比较的容易想到的办法.
使用CFile或是fopen函数去打开这个文件,看是否可以打开此文件.
或是使用文件查找类,去搜索此文件是否存在.CFileFind.
这次讲二个函数.以前没有使用过的.
#include <iostream>
#include  <io.h>

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
 int nRet = _taccess("d:\\肖.xml",0);
 if (nRet==-1)
 {
  cout<<"未能找到此文件"<<endl;
 }
 else
 {
  cout<<"文件存在"<<endl;
 }
 return 0;
}

打开msdn里有对于这个函数的参数说明

Parameters

path
File or directory path.
mode
Permission setting.

mode value Checks file for
00 Existence only
02 Write permission
04 Read permission
06 Read and write permission


看到了.这个mode value 好像专业是为做了检查文件是否存在做了一个value.

还有一个函数.这个是一个Windows Api函数.
GetFileAttributes

发表于 @ 2006年12月07日 16:39:00|评论(loading...)|编辑

新一篇: 如何使用TinyXML来解析xml文档: | 旧一篇: 佛学来理解人生的道理

评论:没有评论。

发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © 风之际