C语言 复制文件夹

用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)
		{
		
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值