在调用fopen之前是否存在文件 [英] file exists or not before calling fopen

查看:125
本文介绍了在调用fopen之前是否存在文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那里,


我试图使用以下方法附加二进制文件:


FILE * strean;


stream = fopen(" c:\ temp.dat"," ba +"));


我有办法吗?

fopen之前可以检查文件是否存在,因为我会通过检查

状态来调用不同的工作流程吗?


提前致谢,

Hi, there,

I am trying to append a binary file by using:

FILE *strean;

stream = fopen( "c:\temp.dat", "ba+" ));

Is there a way that I can check if the file exists or not before
fopen, because I will call different work flow by check the status of
the file?

Thanks in advance,

推荐答案

" Julia"写道:
"Julia" wrote:

>我试图使用以下方法附加二进制文件:

FILE * strean;
stream = fopen(" c:\ temp.dat"," ba +"));

有没有办法在
>I am trying to append a binary file by using:

FILE *strean;

stream = fopen( "c:\temp.dat", "ba+" ));

Is there a way that I can check if the file exists or not before
fopen, because I will call different work flow by check the status of
the file?



您可以尝试以只读模式打开文件,然后再次打开

,在您知道结果后再追加第一个操作。

(或使用系统特定的机制来读取目录等)


请注意,如果环境是多任务的系统,和文件的存在取决于另一个程序,没有办法(在

标准C中)保证文件不是由某人创建的两个fopen()调用之间的
else。


Roberto Waltman


[请回复小组,

返回地址无效]

You can attempt to open the file in read-only mode, and then open it
again for appending after you know the result of the first operation.
(Or use a system-specific mechanism to read the directory, etc.)

Be aware that if environment is a multi-tasking system, and the
existence of the file depends on another program, there is no way (in
standard C) of guaranteeing that the file was not created by somebody
else between the two fopen() calls.

Roberto Waltman

[ Please reply to the group,
return address is invalid ]


Julia写道:
Julia wrote:

那里,


我试图使用以下方法附加二进制文件:


FILE * strean;


stream = fopen(" c:\ temp.dat"," ba +"));
Hi, there,

I am trying to append a binary file by using:

FILE *strean;

stream = fopen( "c:\temp.dat", "ba+" ));



这是一个非常奇特的文件名。您可能希望

在comp.lang.c中查看问题19.17常见问题

问题(FAQ)列表位于< http://c-faq.com/在你去之前

更进一步。

That''s a very peculiar file name. You might want to
review Question 19.17 in the comp.lang.c Frequently Asked
Questions (FAQ) list at <http://c-faq.com/before you go
much further.


有没有办法在
$之前检查文件是否存在b $ b fopen,因为我会通过检查

文件的状态来调用不同的工作流程?
Is there a way that I can check if the file exists or not before
fopen, because I will call different work flow by check the status of
the file?



...这是问题19.11。


-

Eric Sosman
es*****@acm-dot-org.inva 盖子




" Julia" < ju ******** @ yahoo.com写信息

新闻:11 ********************** @ a75g2000cwd.googlegr oups.com ...

"Julia" <ju********@yahoo.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...

那里,


我想附加一个二进制文件使用:


FILE * strean;


stream = fopen(" c:\ temp.dat"," ba + ));


有没有办法可以在

fopen之前检查文件是否存在,因为我将通过以下方式调用不同的工作流程检查

状态的状态?


提前致谢,
Hi, there,

I am trying to append a binary file by using:

FILE *strean;

stream = fopen( "c:\temp.dat", "ba+" ));

Is there a way that I can check if the file exists or not before
fopen, because I will call different work flow by check the status of
the file?

Thanks in advance,



致电后fopen withba +,使用ftell查看你的位置。

-

Fred L. Kleinschmidt

波音助理技术研究员

航空稳定性与控制计算

After you call fopen with "ba+", use ftell to see where you are.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Aero Stability and Controls Computing


这篇关于在调用fopen之前是否存在文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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