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

  • 相关阅读:
    Tizen Sample Web Applications
    Linux下RPM软件包的安装及卸载
    libevent
    GTest 运行参数
    【BBC micro:bit基础教程】02-micro:bit与人体运动检测传感器
    【BBC micro:bit基础教程】01-如何用按键控制一个LED
    CMD下查询Mysql中文乱码的解决方法
    php foreach 使用&(与运算符)引用赋值要注意的问题
    sql必知必会(第四版) 学习笔记一
    test
  • 原文地址:https://www.cnblogs.com/findumars/p/8732315.html
Copyright © 2011-2022 走看看