• 判断文件是否存在的另一种方法 _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

  • 相关阅读:
    3.STM32复位系统
    3.CM3内核架构-寄存器
    2.STM32启动文件
    java线程池
    java多线程
    动态规划(dynamic programming)(二、最优子问题与重叠子问题,以及与贪心的区别)
    SOAP协议
    动态规划(dynamic programming)(一、简介,举例)
    红黑树-RBT(二、基本操作之插入)
    红黑树-RBT(二、基本操作之左旋)
  • 原文地址:https://www.cnblogs.com/findumars/p/8732315.html
Copyright © 2020-2023  润新知