欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

VC++ 使用 _access函數(shù)判斷文件或文件夾是否存在

 更新時(shí)間:2015年10月27日 08:59:30   投稿:hebedich  
這篇文章主要介紹了VC++ 使用 _access函數(shù)判斷文件或文件夾是否存在的相關(guān)資料,需要的朋友可以參考下

_access函數(shù)

int _access( 
 const char *path, 
 int mode 
);
int _waccess( 
 const wchar_t *path, 
 int mode 
);

參數(shù)

path
文件或目錄路徑。

mode
讀/寫(xiě)特性。

返回值
 
如果文件包含特定模式,每個(gè)函數(shù)返回 0。 函數(shù)返回 - 1,則名稱文件不存在或不具有特定模式;在這種情況下,如下表errno 所示設(shè)置。

EACCES

訪問(wèn)被拒絕:文件權(quán)限的設(shè)置不允許指定的訪問(wèn)權(quán)限。

ENOENT

未找到文件名或路徑。

EINVAL

無(wú)效參數(shù)。

備注

當(dāng)使用文件,_access 函數(shù)確定指定的文件或目錄是否存在并且具有指定值的特性 mode。 在使用與目錄,_access 確定指定的目錄是否存在;只有在 Windows 2000 和更高版本的操作系統(tǒng)上,所有目錄讀取和寫(xiě)入權(quán)限。

mode 值

檢查文件。

00

僅存在

02

Write-only

04

只讀

06

讀取和寫(xiě)入

最后給大家簡(jiǎn)單匯總下VC++用于判斷文件文件夾是否存在的方法

推薦實(shí)例例:

if(::GetFileAttributes(m_filename)==-1){//文件不存在}else{//文件存在}

1. 使用_access函數(shù),函數(shù)原型為 int _access( const char *path, int mode );

2. 使用CreateFile函數(shù),函數(shù)原型為: HANDLE CreateFile( LPCTSTR lpFileName, // pointer to name of the file DWORD dwDesiredAccess, // access (read-write) mode DWORD dwShareMode, // share mode LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security attributes DWORD dwCreationDisposition, // how to create DWORD dwFlagsAndAttributes, // file attributes HANDLE hTemplateFile // handle to file with attributes to // copy );

3. 使用FindFirstFile函數(shù),函數(shù)原型為: HANDLE FindFirstFile( LPCTSTR lpFileName, // pointer to name of file to search for LPWIN32_FIND_DATA lpFindFileData // pointer to returned information );

4. 使用GetFileAttributes函數(shù),函數(shù)原型如下: DWORD GetFileAttributes( LPCTSTR lpFileName // pointer to the name of a file or directory );

5. 使用Shell Lightweight Utility APIs函數(shù) PathFileExists()專門(mén)判斷文件和目錄時(shí)否存在的函數(shù)文件名可讀性比較強(qiáng)還可以判斷目錄是否存在 Header: Declared in Shlwapi.h Import Library: Shlwapi.lib 以上的各種方法供參考,函數(shù)具體用法需參見(jiàn)MSDN

相關(guān)文章

最新評(píng)論