如何在用户指定的文件夹中创建文件夹和文件?
这是我职能的一部分:
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/