1155 views|0 replies

2015

Posts

0

Resources
The OP
 

Use of C language library function access [Copy link]

Another way to use the C language library:

Function name: access
Function: Determine the access rights of a file
Usage: int access(const char *filenames, int amode);
Program example:
#include <stdio.h>
#include <io.h>

int file_exists(char *filename);

int main(void)
{
printf("Does NOTEXIST.FIL exist: %s/n",
file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
return 0;
}

int file_exists(char *filename)
{
return (access(filename, 0) == 0);
}

access(filename, 0)0 means to check whether the file exists

finename file name mode mode, 5 modes in total:

0 - Check if the file exists

1- Check if the file is executable

2- Check if the file has write access

4- Check if the file is readable

6- Check if the file has read/write access

When access returns a value of 0, it means existence, and when it returns -1, it means failure.

if(access(_Filename,0) == 0)
printf("exists");
else
does not exist.

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list