当前位置:网站首页>C语言判断文件或文件夹是否存在
C语言判断文件或文件夹是否存在
2022-06-10 20:51:00 【m0_60721514】
C语言判断文件或文件夹是否存在
汇总网上搜集的资料,总结了下述几种方法用于判断文件或者文件夹是否存在,注意每个函数的头文件引用。
一、使用access
函数定义
#include <unistd.h>
int access(const char * pathname, int mode);函数说明
可用于判断文件或者目录是否存在, access()会检查是否可以读/写某一已存在的文件,access()只作权限的核查, 并不理会文件形态或文件内容,因此,如果一目录表示为"可写入",表示可以在该目录中建立新文件等操作,而非意味此目录可以被当做文件处理
pathname为文件或文件夹的路径,当前目录直接使用文件或文件夹名;mode表示检查模式,共4种模式:
R_OK, 4只判断是否有读权限,对应宏定义里面的00 只存在W_OK, 2只判断是否有写权限,对应宏定义里面的02 写权限X_OK, 1判断是否有执行权限,对应宏定义里面的04 读权限F_OK, 0只判断是否存在,对应宏定义里面的05 读和写权限
- 返回值
如果指定的存取方式有效,则函数返回0,否
边栏推荐
- Which city should I go to after I graduate from it? Which position has a high salary? Which companies have good treatment?
- Abbexa cdan1 siRNA instruction manual
- Can I make up the exam if I fail the soft exam? Here comes the answer
- C language -- 10 first knowledge of structure
- [nk] 牛客月赛51 G计算题
- MySQL数据库如何查看表占用空间大小
- Leetcode advanced road - 136 A number that appears only once
- C language ---2 initial knowledge of data types
- 字符串 反转
- JS mobile terminal copy text to clipboard code
猜你喜欢
随机推荐
Detailed steps and actual records of SQL server2019 installation (available for hands-on test)
Principle of gravure overprint and factors affecting overprint
自媒体视频创作如何选择领域?
【MySQL】表数据的增删查改(DML)
[qingniaochangping campus of Peking University] the coordinated development of vocational education and general education, will this year's high school entrance examination be easy?
Abbexa low sample size chicken lysozyme C (Lyz) ELISA Kit
If else is too easy to use? (understanding this article will further improve your logic)
Record today's MySQL failures
Notes to entry: do I need to know programming for O & M?
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated
Detailed explanation of Lora module wireless transceiver communication technology
Can I make up the exam if I fail the soft exam? Here comes the answer
Leetcode advanced path - Search insertion location
Introduction to database system -- Chapter 1 -- Introduction (important knowledge points)
[1024 ways to play windows azure] 75 Fast cloud database migration seamlessly migrate alicloud RDS SQL server to azure SQL databas
C language ---9 first knowledge of macros and pointers
Anti shake and throttling
Shell implements SSH login and executes commands
NFT版权/版税
Exec function of PHP









