在VC裏如何檢查一個文件是否存在

有一個比較的容易想到的辦法.
使用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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章