VC++ USES the _access function to determine whether a file or folder exists
- 2020-05-05 11:41:09
- OfStack
_access function
int _access(
const char *path,
int mode
);
int _waccess(
const wchar_t *path,
int mode
);
Parameter
path
File or directory path.
mode
Read/write feature.
The return value
Each function returns 0 if the file contains a specific pattern. If the function returns -1, the name file does not exist or has a specific pattern. In this case, the Settings are shown in table errno below.
EACCES
Access denied: the file permissions Settings do not allow the specified access permissions.
ENOENT
Filename or path not found.
EINVAL
Invalid parameter.
Note
When using a file, the _access function determines whether the specified file or directory exists and has the property mode with the specified value. In use with directory, _access determines whether the specified directory exists; Only on Windows 2000 and later operating systems do all directories have read and write permissions.
mode 值 |
检查文件。 |
---|---|
00 |
仅存在 |
02 |
Write-only |
04 |
只读 |
06 |
读取和写入 |
Finally, I will give you a brief summary of VC++ to determine the existence of the file folder
Recommended example :
if(::GetFileAttributes(m_filename)==-1){// file does not exist}else{// file does exist}
1. Use the _access function, whose prototype is int _access(const char *path, int mode);
2. Using CreateFile function, the function prototype is: HANDLE CreateFile(LPCTSTR lpFileName, // pointer to name of file dwDesiredAccess, // access (read-write) mode DWORD dwShareMode, // share mode LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security attributes DWORD dwCreationDisposition, // how to create dwFlagsAndAttributes, // file attributes HANDLE hTemplateFile // handle to file with attributes to // copy);
3. Use FindFirstFile function, the function prototype is: HANDLE FindFirstFile(LPCTSTR lpFileName, // pointer to name name FindFirstFile to LPWIN32_FIND_lpFindFileData pointer to information);
4. Using the GetFileAttributes function, the function prototype is as follows: DWORD GetFileAttributes(LPCTSTR lpFileName // pointer to the name of file or directory);
5. Shell Lightweight Utility APIs function PathFileExists () is used to determine whether files and directories exist or not. The file name of the function is more readable