zoukankan      html  css  js  c++  java
  • 判断文件是否存在的另一种方法 _access 和 _waccess

    函数原型:

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

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

    示例代码:

    [cpp] view plain copy
     
    1. #include <io.h>  
    2. #include <stdio.h>  
    3. #include <stdlib.h>  
    4.   
    5. int _tmain(int argc, _TCHAR* argv[])  
    6. {  
    7.     //如果文件具有指定的访问权限,则函数返回0  
    8.     //如果文件不存在或者不能访问指定的权限,则返回-1  
    9.   
    10.     //备注  
    11.     //当path为文件时,_access函数判断文件是否存在,并判断文件是否可以用mode值指定的模式进行访问  
    12.     //当path为目录时,_access只判断指定的目录是否存在,在WindowsNT和Windows2000中,所有目录都有读写权限  
    13.   
    14.     //mode值  
    15.     //00    只检查文件是否存在  
    16.     //02    写权限  
    17.     //04    读权限  
    18.     //06    读写权限  
    19.   
    20.     //_waccess是_access的宽字符版本  
    21.     if (_access("demo.txt", 0) != -1)  
    22.     {  
    23.         printf("the demo.txt exist ");  
    24.   
    25.         //判断文件是否可写,假定文件是只读的  
    26.         if (_access("demo.txt", 2) == -1)  
    27.         {  
    28.             printf("the demo.txt does not have write permission ");  
    29.         }  
    30.         else  
    31.         {  
    32.             printf("the demo.txt have write permission ");  
    33.         }  
    34.     }  
    35.     else  
    36.     {  
    37.         printf("the demo.txt does not exist ");  
    38.     }  
    39.   
    40.     system("pause");  
    41.     return 0;  
    42. }  

    https://blog.csdn.net/hellokandy/article/details/78471006

  • 相关阅读:
    Java运算符号,对象赋值,别名
    斐波那契数列的应用
    递归问题------汉诺塔
    字符串变量小议
    编程题之合并两个有序的数组
    线程/进程的区别之小议(二)
    线程/进程的区别之小议(一)
    OSI 七层模型
    TCP/IP 四层模型
    c语言程序开发过程,编译的完整过程
  • 原文地址:https://www.cnblogs.com/findumars/p/8732315.html
Copyright © 2011-2022 走看看