Another way to determine if a file exists _access and _waccess

Source: Internet
Author: User

Function Prototypes:

int _access (const char *path, int mode );

int _waccess (const wchar_t *path, int mode );

Example code:

[CPP]View PlainCopy
  1. #include <io.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. int _tmain (int argc, _tchar* argv[])
  5. {
  6. //If the file has the specified access rights, the function returns 0
  7. returns 1 if the file does not exist or does not have access to the specified permission
  8. //Notes
  9. //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
  10. //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
  11. //mode Value
  12. //00 checks whether the file exists
  13. //02 Write Permissions
  14. //04 Read Permissions
  15. //06 Read and Write permissions
  16. //_waccess is a wide-character version of _access
  17. if (_access ("Demo.txt", 0)! =-1)
  18. {
  19. printf ("The Demo.txt exist\n");
  20. //Determine if the file is writable, assuming the file is read-only
  21. if (_access ("Demo.txt", 2) = =-1)
  22. {
  23. printf ("The demo.txt does not having write permission\n");
  24. }
  25. Else
  26. {
  27. printf ("The Demo.txt has write permission\n");
  28. }
  29. }
  30. Else
  31. {
  32. printf ("The demo.txt does not exist\n");
  33. }
  34. System ("pause");
  35. return 0;
  36. }

78471006

Another way to determine if a file exists _access and _waccess

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.