📄 mycopy.h
字号:
#include<sys/types.h>#include<dirent.h>#include<unistd.h>#include<stdio.h>int isdir(char *str){ DIR *dir; if((dir=opendir(str))==NULL) return 0; else closedir(dir);}int isfile(char *str){ FILE * fp; fp=fopen(str,"r+"); if(fp==NULL) return 0; else { fclose(fp); return 1; }}int copyfile(char*sourcefile,char*targetfile){ FILE *source,*target; if((source=fopen(sourcefile,"r+"))==NULL) { printf("open source file error\n"); return 0; } if((target=fopen(targetfile,"w"))==NULL) { printf("open target file error\n"); return 0; } char buf[80]; while(fgets(buf,80,source)) fputs(buf,target); fclose(target); fclose(source); printf("%s\n","copy success"); return 1;}int filetodir(char *source,char *target){ char name[80]; strcpy(name,source); strcpy(name,strcat(name,"/")); strcpy(name,strcat(name,target)); copyfile(source,name);}int dirtodir(char *source,char *target){ char *childdir; DIR *dp; struct dirent *dirp; dp = opendir(source); while( (dirp = readdir(dp) )!=NULL) { if(strcmp(".",dirp->d_name)!=0&&strcmp("..",dirp->d_name)!=0) filetodir(dirp->d_name,target); }}void mycopy(char *source,char *target){ if(isfile(source)==1&&isfile(target)==0&&isdir(target)==0) copyfile(source,target); else if(isfile(source)==1&&isfile(target)==1&&isdir(target)==0) copyfile(source,target); else if(isfile(source)==1&&isdir(target)==1) filetodir(source,target); else if(isdir(source)==1&&isdir(target)==1) dirtodir(source,target); else printf("Instruction is wrong!\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -