用C语言编写一个程序,运行程序时,附上参数(想要复制的文件夹,以及目标文件夹)
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<unistd.h>
#include<string.h>
#include<strings.h>
#include<errno.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<fcntl.h>
#include<dirent.h>
#include<time.h>
int is_dir( char* file_name);
void cp_file( char *source_path , char *destination_path)
{
FILE* fp_src = NULL;
FILE* fp_dst = NULL;
// int in,out;
if((fp_src = fopen(source_path,"r"))==NULL){//打开源文件的文件流
printf("源文件打开失败!\n");
exit(1);
}
if((fp_dst=fopen(destination_path,"w"))==NULL){//打开目标文件的文件流
printf("目标文件创建失败!\n");
exit(1);
}
int c, total = 0;
while(1)
{
c = fgetc( fp_src);
if( c == EOF && feof(fp_src))
{
break;
}
else if( ferror(fp_src))
{
perror("fget()");
break;
}
fputc(c,fp_dst);
}
fclose(fp_src);
fclose(fp_dst);
}
int endwith(char* s,char c){//用于判断字符串结尾是否为“.”
printf("end : %c\n",s[strlen(s)-1]);
if(s[strlen(s)-1]==c){
return 1;
}
else{
return 0;
}
}
void copy_folder(char* source_path,char *destination_path)
{
DIR *dst_dp = opendir(destination_path);
if(dst_dp == NULL)// if destination_path is not exist , mkdir new one
{
printf(" your dest dir is not existed \n");
printf(" system will mkdir for U \n");
if(mkdir(destination_path,0777) == -1)
{