一个简单的判断文件是否存在的WIN API函数

摘要:
int_访问;int-waccess;您可以确定文件路径是否存在。如果返回-1,则文件不存在或无法在指定模式下访问。如果指定了目录,则只有该目录不存在。

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

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

可以判断文件是否path存在。

mode                Checks file for

00                    Existence only

02                    Write-only

04                    Read-only

06                    Read and write

功能 :  判断是否允许访问。

返回值: 

返回0,则文件为指定的模式。返回-1,则文件不存在或者不能用指定的模式访问。如果在指定的是目录,则仅仅是目录不存在。

Requirements


Routine
Required header
Optional headers
Compatibility

_access

<io.h>

<errno.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_waccess

<wchar.h> or <io.h>

<errno.h>

Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003


sample code:

// 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.\n" );

        // 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.\n" );
    }
}
 
参考: Msdn

免责声明:文章转载自《一个简单的判断文件是否存在的WIN API函数》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇EFCore扩展Select方法(根据实体定制查询语句)AttributeError: 'WebDriver' object has no attribute 'switchTo'下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Windows API参考大全(转)

具体用法请参考msdn 1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAddConnection3 创建同一个网络资源的连接 WNetCancelConnection 结束一个网络连接 WNetCancelConnection2 结束一个...

Nginx 反向代理解决跨域问题

server { listen 8080; server_name localhost; location / { proxy_pass http://111.111.111.111:8080; # 代理的地址 proxy_http_version 1.1;...

服务端跨域处理 Cors

1 添加System.Web.Cors,System.Web.Http.Cors 2 global文件中 注册asp.net 管道事件 protected void Application_BeginRequest(objectsender, EventArgs e) { var response...

编译安装squid3.1亲测

编译安装Squid2.6 1,设置“文件描述符”,并设置用户同时打开文件数量 # vi /usr/include/bits/typesizes.h # vi /usr/include/linux/posix_types.h 把里边的 #define __FD_SETSIZE 1024 改成 65536 2,设置当前环境 # ulimit -Hs 65536...

CORS跨域实现思路及相关解决方案

本篇包括以下内容: CORS 定义 CORS 对比 JSONP CORS,BROWSER支持情况 主要用途 Ajax请求跨域资源的异常 CORS 实现思路 安全说明 CORS 几种解决方案 自定义CORSFilter Nginx 配置支持Ajax跨域 支持多域名配置的CORS Filter keyword:cors,跨域,ajax,403,fi...

java后台解决跨域问题

解决跨域问题的方式有很多,这里主要是添加注解的方式和采用添加拦截器的方法: 方法一、spring boot中只用在Controller类上添加一个“@CrossOrigin“注解就可以实现对当前controller 的跨域 访问了,当然这个标签也可以加到方法上。 @CrossOrigin public classCommonController { }...