如何检查文件是否在C存在 [英] How to check if a file exists in c
问题描述
我有一个连接到它的名称或有时只有名称核心PID生成的核心文件。我需要检查,如果一个文件名 core.pid
或核心
存在。我已经尝试使用 STAT()
,我使用的路径字符串的/ tmp /核心*
,但失败了。可否请您让我知道如何解决this.Thanks您的时间。
I have core files generated with the pid attached to its name or sometimes only the name core. I need to check if a file exists with name core.pid
or core
. I have tried using stat()
where I used the path string as /tmp/core*
, but failed. Can you please let me know how to solve this.Thanks for your time.
推荐答案
由于您使用Linux,你可以使用
Since you're using Linux, you can use
http://man7.org/linux/man-pages/ man3 / glob.3.html
水珠会读取目录并返回匹配模式名称的列表,这是你想要什么。
glob will read a directory and return a list of names matching a pattern, which is just what you want.
您可能还需要使用 http://man7.org/ Linux的/人工页/ man7 / inotify.7.html 以只读的目录时,它改变了。
You also might want to use http://man7.org/linux/man-pages/man7/inotify.7.html to only read the directory when it changes.
这篇关于如何检查文件是否在C存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!