编程的时候经常要确定某一个文件是否存在。
以前我会用CreateFile去尝试打开一个文件,然后看GetLastError是否是0x2,即ERROR_FILE_NOT_FOUND
这里插一句:
在微软的MSDN上, System Error Codes 有16000条,defined in the WinError.h 。参考
有一次我用exeScope看QQ音乐里面的DLL的时候,我发现了这个函数:PathFileExists
语法是
BOOL PathFileExists(
__in LPCTSTR pszPath
);
Determines whether a path to a file system object such as a file or folder is valid.
还可以判断文件夹是否valid
TRUE if the file exists; otherwise, FALSE.
如果文件系统对象存在返回TRUE,否则返回FALSE。
如果用VC的话,需要
#pragma comment(lib,"shlwapi.lib")
#include <shlwapi.h>