一、判斷文件夾是否存在:
1. _access, _waccess
http://msdn.microsoft.com/zh-tw/library/vstudio/1w06ktdy(v=vs.90).aspx
2. CFileFind 遍歷目錄判斷是否存在
http://msdn.microsoft.com/en-US/library/scx99850(v=vs.80).aspx
3. PathIsDirectory
http://msdn.microsoft.com/en-us/library/bb773621(VS.85).aspx
二、判斷文件是否存在:
1. _access, _waccess
http://msdn.microsoft.com/zh-tw/library/vstudio/1w06ktdy(v=vs.90).aspx
2. CFileFind 遍歷目錄判斷是否存在
http://msdn.microsoft.com/en-US/library/scx99850(v=vs.80).aspx
-
3. 使用CreateFile函數,函數原型爲: HANDLE CreateFile(
LPCTSTR lpFileName, // pointer to name of the file
LPCTSTR lpFileName, // pointer to name of the file
DWORD dwDesiredAccess, // access (read-write) mode
DWORDdwShareMode, // 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
);
DWORD dwDesiredAccess, // access (read-write) mode
DWORDdwShareMode, // 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
); -
4. 使用FindFirstFile函數,函數原型爲: HANDLE FindFirstFile(
LPCTSTR lpFileName, // pointer to name of file to search for
LPWIN32_FIND_DATA lpFindFileData
// pointer to returned information
); -
5. 使用GetFileAttributes函數,函數原型如下: DWORD GetFileAttributes(
LPCTSTR lpFileName // pointer to the name of a file or directory
); -
6. 使用Shell Lightweight Utility APIs函數PathFileExists()專門判斷文件和目錄時否存在的函數文件名可讀性比較強還可以判斷目錄是否存在Header: Declared in Shlwapi.h
Import Library: Shlwapi.lib
以上的各種方法供參考,函數具體用法需參見MSDN。