C 创建用户指定的文件和文件夹

标签 c file directory

如何在用户指定的文件夹中创建文件夹和文件?

这是我职能的一部分:

char* folder = *(argv + 2); //"C:\\Users\\User\\Desktop\\New folder";
if (!(log = fopen("folder\\file.txt", "a")))// checking if there is any problem with the file
    {
        printf("The log file has not created correctly, closing the program\n");
        system("PAUSE");
        exit(1);
    } 

最佳答案

要么我不明白你的问题,要么它太简单了。让我们假设它太简单了。然后你可以这样做:

char filename[1024];
FILE *logfp;
sprintf(filename, "%s\\file.txt", argv[2]);
if ((logfp=fopen(filename,"w")==NULL) {
    //...error etc.

注意:这假定路径中的所有目录都存在。

关于C 创建用户指定的文件和文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37194873/

相关文章:

ruby - 内置在 ruby​​ 目录中列出目录的方法

security - 什么是目录列表漏洞?

c - 从 C 中的文件读取时出现段错误

c - C中的文件创建权限

c# - 目录大小改变事件

linux - 确定文件中出现哪些字符的命令

c - 读取数据文件并存储到结构数组中

c - 排列矩阵?

c - 在 Web 服务器上运行 gdb

c - C 中 while 循环中的 Fork 炸弹,在退出程序后发生