zoukankan      html  css  js  c++  java
  • [转载]判断文件是否存在


    来自:http://blog.chinaunix.net/uid-29121609-id-3886397.html
    _access() 检验文件的模式
    返回值:0表示允许访问,-1表示禁止访问。
    函数原型:
    int _access( 
       const char *path, 
       int mode 
    );
    另外有宽字符的:
    int _waccess( 
       const wchar_t *path, 
       int mode 
    );
    mode value Checks file for

    00

    Existence only

    02

    Write-only

    04

    Read-only

    06

    Read and write

    这个函数只检查文件和目录是否是只读的,它不检查文件系统安全设置。

    返回值 文件具有给定的模式返回0,如果文件不存在或没有给定的模式,返回-1

    EACCESS(拒绝访问:文件的权限设置不允许指定的访问),

    ENOENT(文件名或路径未找到),

    EINVAL(无效的参数).

    例子:

    // crt_access.c
    // compile with: /W1
    // This example uses _access to check the file named
    // crt_ACCESS.C to see if it exists and if writing is allowed.
    
    #include  <io.h>
    #include  <stdio.h>
    #include  <stdlib.h>
    
    int main( void )
    {
        // Check for existence.
        if( (_access( "crt_ACCESS.C", 0 )) != -1 )
        {
            printf_s( "File crt_ACCESS.C exists.
    " );
    
            // Check for write permission.
            // Assume file is read-only.
            if( (_access( "crt_ACCESS.C", 2 )) == -1 )
                printf_s( "File crt_ACCESS.C does not have write permission.
    " );
        }
    }
  • 相关阅读:
    arrayObj.splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]])
    运算符 ||
    ajax 本地测试,使用Chrome 浏览器
    js set
    js get 传参 汉字 乱码问题
    删除对象中的key
    html 返回页面顶部
    js 设置回车事件
    盘面,盘口
    ST股
  • 原文地址:https://www.cnblogs.com/ruichenduo/p/4398286.html
Copyright © 2011-2022 走看看