VC 判斷檔案是否存在

2021-05-23 00:04:02 字數 1145 閱讀 6522

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

2. 使用createfile函式,函式原型為:

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函式,函式原型為:

handle findfirstfile( lpctstr lpfilename, // pointer to name of file to search for

lpwin32_find_data lpfindfiledata // pointer to returned information

); 4. 使用getfileattributes函式,函式原型如下:

dword getfileattributes( lpctstr lpfilename // pointer to the name of a file or directory );

5. 使用shell lightweight utility apis函式 pathfileexists()專門判斷檔案和目錄時否存在的函式檔名可讀性比較強還可以判斷目錄是否存在 header: declared in shlwapi.h import library: shlwapi.lib 以上的各種方法供參考,函式具體用法需參見msdn。

方法1:

方法2:

方法3:

方法4:

方法5:

VC下判斷檔案是否存在

方法1 include include include void main void 方法2 if invalid handle value createfile d a.txt generic read,file share read,null,open existing,file attribu...

VC下判斷檔案是否存在

方法1 include include include void main void 方法2 if invalid handle value createfile d a.txt generic read,file share read,null,open existing,file attribu...

VC下判斷檔案是否存在

方法1 include include include void main void 方法2 if invalid handle value createfile d a.txt generic read,file share read,null,open existing,file attribu...