如何用c语言将文件复制到自己想要的文件夹??

2025-02-27 13:37:40
推荐回答(3个)
回答1:

C语言里的system("");函数可以执行命令行的几乎所有指令,把命令行输入的内容作为参数传入即可。复制文件的话 应该是:copy 源文件 目的路径。
例如命令行里的 copy c:\test.txt d:\text.txt,
也就是C语言里的:system("copy c:\test.txt d:\text.txt");
或者这样
char c[50] = "copy c:\test.txt d:\text.txt";
system(c);

回答2:

包含库stdlib.h
然后调用system函数,使用命令行来解决。
copy:复制文件。
md:创建文件夹

在while之后执行:
system("md 你要复制到的路径");
system("copy 输入文件 输出文件");
注意:输出文件必须包括路径。
至于system参数中字符串的合并就你自己弄咯!^_^

回答3:

#include 
#include 

int main() {
FILE *in,*out;
char infile[50],outfile[50];
printf ("Enter the infile name:");
scanf ("%s",infile);
printf ("Enter the outfile name:");
scanf("%s",outfile);
if((in = fopen(infile,"r")) == NULL) {
printf("cannot open %s.\n",infile);
exit(0);
}
if((out = fopen (outfile,"w"))==NULL) {
printf ("cannot open %s.\n",outfile);
exit(0);
}
while(!feof(in))fputc(fgetc(in),out);
fclose(in);
fclose(out);
return 0;
}