如何在fopen创建文件夹? [英] How to create folder at fopen?

查看:467
本文介绍了如何在fopen创建文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我的问题很简单,但是虽然像野外一样搜索我无法找到解决方案。

我只想附加到一个文件,让's'说到c:\ my folder \ filename1.txt。


通常使用append-option,如果文件不存在,则创建该文件。但是我还想要创建文件夹(如果它不存在) - 现在如果

指定的文件夹不可用,则根本不会创建该文件。


fopen还有一个额外的选项,我找不到或者没有

其他有用的功能就是这样做的吗?


tschi-p

解决方案

tschi-p< ts ***** @ yahoo.com>写道:

也许我的问题很简单,但是虽然像野外搜索我无法找到解决方案。
我只是想附加到一个文件,让我们说到c:\ my folder \ filename1.txt。


小心退格,你可能需要比你在这里显示的更多;-)

通常使用append-option,如果没有,则创建文件不存在。但是我还想要创建文件夹(如果它不存在) - 现在如果
指定的文件夹不可用,则根本不创建该文件。
fopen还有一个额外的选项,我找不到或没有
其他有用的功能吗?




否,没有。那是因为C标准甚至不承认存在文件夹。所以与文件夹有关(目录

来自UNIX阵营的那些;-)必须使用系统特定的

函数来完成。也许你的系统有一些功能(甚至扩展名为
到fopen()))可以满足您的需求,但就此而言,你需要在一组中询问处理你的系统。


问候,Jens

-

\ Jens Thoms Toerring ___ 济*********** @ physik.fu-berlin.de

\ __________________________ http://www.toerring.de


<济*********** @ physik.fu-berlin.de>在消息中写道

news:2p ************ @ uni-berlin.de ...

tschi-p< ts * ****@yahoo.com>写道:

也许我的问题很简单,但是虽然像野外搜索一样我找不到解决方案。
我只是想附加到一个文件,让我们说toc:\ my


folder \ filename1.txt" ;.
小心退格,




这让我眨了一下。 :-)


我敢肯定你的意思是''反斜杠''。


" c:\\我的文件夹\\filename1.txt"


然而,Windows(我假设OP正在使用,从他的

提到''''文件夹''),也会接受正斜杠为

路径分隔符:


" c:/ my folder / filename1.txt"。


-Mike




" tschi-p" < TS ***** @ yahoo.com>写了


通常使用append-option,如果文件不存在,则创建该文件。但是
我还想要创建的文件夹(如果它不存在) - 现在如果
指定的文件夹不可用,则根本不会创建该文件。

在fopen还有一个额外的选项,我找不到或者是否有其他有用的函数可以做到这一点?



这完全取决于操作系统。有些人可能会在传递给fopen()的路径时创建一个文件夹

,大部分都没有。您需要使用特定于平台的

函数来使用目录服务。这很刺激,但这就是标准所说的



maybe my question is quite simple, but although searching like wild I cannot
find a solution.
I just want to append to a file, let''s say to "c:\my folder\filename1.txt".

Normally with append-option, the file is created if it doesn''t exist. But I
want also the folder to be created if it does not exist - now if the
specified folder is not available, the file isn''t created at all.

Is there an additional option at fopen that I couldn''t find or are there
other useful functions that do exactly this?

tschi-p

解决方案

tschi-p <ts*****@yahoo.com> wrote:

maybe my question is quite simple, but although searching like wild I cannot
find a solution.
I just want to append to a file, let''s say to "c:\my folder\filename1.txt".
Be careful with the backspaces, you may need more than you show here;-)
Normally with append-option, the file is created if it doesn''t exist. But I
want also the folder to be created if it does not exist - now if the
specified folder is not available, the file isn''t created at all. Is there an additional option at fopen that I couldn''t find or are there
other useful functions that do exactly this?



No, there isn''t. That''s because the C standard doesn''t even admit
that folders exist. So everything to do with folders (directories
for those from the UNIX camp;-) has to be done using system specific
functions. Perhaps your system has some functions (or even extensions
to fopen())) that does what you are looking for, but about this you
have to ask in a group that deals with your system.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de


<Je***********@physik.fu-berlin.de> wrote in message
news:2p************@uni-berlin.de...

tschi-p <ts*****@yahoo.com> wrote:

maybe my question is quite simple, but although searching like wild I cannot find a solution.
I just want to append to a file, let''s say to "c:\my

folder\filename1.txt".
Be careful with the backspaces,



That made me blink for a minute. :-)

I''m sure you meant to say ''backslashes''.

"c:\\my folder\\filename1.txt"

However, Windows (which I''ll assume OP is using, from his
mention of ''folder''), will also accept forward slash as
path separator:

"c:/my folder/filename1.txt".

-Mike



"tschi-p" <ts*****@yahoo.com> wrote


Normally with append-option, the file is created if it doesn''t exist. But I want also the folder to be created if it does not exist - now if the
specified folder is not available, the file isn''t created at all.

Is there an additional option at fopen that I couldn''t find or are there
other useful functions that do exactly this?


This is entirely up to the OS. Some may create a folder when passed as part
of a path to fopen(), most do not. You need to use platform-specific
functions to use the directory services. This is irritating, but that''s what
the standard says.


这篇关于如何在fopen创建文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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