Function Prototypes:
int _access (const char *path, int mode );
int _waccess (const wchar_t *path, int mode );
Example code:
[CPP]View PlainCopy
- #include <io.h>
- #include <stdio.h>
- #include <stdlib.h>
- int _tmain (int argc, _tchar* argv[])
- {
- //If the file has the specified access rights, the function returns 0
- returns 1 if the file does not exist or does not have access to the specified permission
- //Notes
- //When path is a file, the _access function determines whether the file exists and determines whether the file can be accessed in the mode specified by the model value
- //When path is a directory, _access only determines whether the specified directory exists, and in WindowsNT and Windows2000, all directories have read and write permissions
- //mode Value
- //00 checks whether the file exists
- //02 Write Permissions
- //04 Read Permissions
- //06 Read and Write permissions
- //_waccess is a wide-character version of _access
- if (_access ("Demo.txt", 0)! =-1)
- {
- printf ("The Demo.txt exist\n");
- //Determine if the file is writable, assuming the file is read-only
- if (_access ("Demo.txt", 2) = =-1)
- {
- printf ("The demo.txt does not having write permission\n");
- }
- Else
- {
- printf ("The Demo.txt has write permission\n");
- }
- }
- Else
- {
- printf ("The demo.txt does not exist\n");
- }
- System ("pause");
- return 0;
- }
78471006
Another way to determine if a file exists _access and _waccess