如何判断一个文件是否存在的几种方法
1, int _access( const char *path, int mode );
要判断的模式
在头文件unistd.h中的预定义如下:
#define R_OK 4 /* Test for read permission. */
#define W_OK 2 /* Test for write permission. */
#define X_OK 1 /* Test for execute permission. */
#define F_OK 0 /* Test for existence. */
具体含义如下:
R_OK 只判断是否有读权限
W_OK 只判断是否有写权限
X_OK 判断是否有执行权限
F_OK 只判断是否存在
2,CreateFile
3,FindFirstFile
4,DWORD GetFileAttributes( LPCTSTR lpFileName // pointer to the name of a file or directory );
如果函数成功,返回值包含文件或目录的属性(属性列表见备注)。如果函数失败,返回值是INVALID_FILE_ATTRIBUTES。