如何使用C文件I / O检查文件是否已存在? [英] How do I check if a file already exists using C file I/O?

查看:145
本文介绍了如何使用C文件I / O检查文件是否已存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c中创建了一个dbms项目,我想检查该文件在该位置是否存在。



我尝试了什么:



i尝试用fopen中的r打开文件,但它创建新文件

i am making a dbms project in c for which i want to check file doesnt exist in that location.

What I have tried:

i try to open file with "r" in fopen but it creates new file

推荐答案

您可以使用访问权限 [ ^ ]标准C库的功能(模式 F_OK )。



但是,尝试打开文件进行读取不应该创建文件,也可以用来检查文件是否存在。
You may use the access[^] function of the standard C library (with mode F_OK).

However, trying to open a file for reading should not create the file and can be also used to check if a file exists.


看看这个 [ ^ ]链接,它可能包含您要查找的内容。
Have a look at this [^] link, it may contain what you are looking for.


这篇关于如何使用C文件I / O检查文件是否已存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆