将文件添加到文件夹 [英] Add file into folder

查看:116
本文介绍了将文件添加到文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我想将文件"a.txt"写入D:\ program,我做了
FILE* f=fopen("D:\program\a.txt","wb").
我只希望文件的路径为D:\ program,但
FILE* f=fopen("D:\program","wb") is wrong.

解决方案

很难精确地说,但有两件事浮现在脑海:
1)您正在尝试在D:盘的根目录中创建一个名为"program"的文件,其中已经包含一个名为"program"的文件夹.
2)您试图在D:磁盘的根目录中创建一个名为"program"的文件,其中不包含此类文件或文件夹.

如果是第一种情况:

是的,那是错误的.
您希望发生什么?
这样看:
在文件柜中输入字母时,是否尝试将所有字母写在文件分隔符上?还是在插入文件分隔符的单张纸上?

使用fopen时,您必须指定文件名,否则您将尝试写到该文件夹​​中,这是不允许的.

如果是第二种情况:

您是否有权写入D:驱动器的根目录? ("C:\\ test",NULL);


我要创建输出目录并保存"a.txt".
我不确定< windows.h>
你能帮我吗?


For example, I want to write file "a.txt" into D:\program, and I did
FILE* f=fopen("D:\program\a.txt","wb").
I only want the path of file to be D:\program, but
FILE* f=fopen("D:\program","wb") is wrong.

解决方案

Difficult to be precise, but there are two things that pop to mind:
1) You are trying to create a file called "program" in the root of the D: disk which contains a folder called "program" allready.
2) You are trying to create a file called "program" in the root of the D: disk which contains no such file or folder.

If the first case:

Yes, that is wrong.
What do you expect to happen?
Look at it this way:
When you file a letter in a file cabinet, do you try to write all letters on the file divider? Or on individual sheets of paper that you insert into the file divider?

You must specify the file name when you use fopen or you are trying to write to the folder, which you are not allowed to do.

If the second case:

Do you have permission to write to the root directory of the D: drive?


Didn''t understand your question, anyway if you are trying to create a diretory use function CreateDirectory , like CreateDirectory("C:\\test",NULL);


I want to create output directory and save "a.txt".
I''m not sure about <windows.h>
Can you help me?


这篇关于将文件添加到文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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