//盗墓者是个丑奴儿,原
//博主个人网站 :
//打完一波小广告,进入正题
//头文件引入
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <dirent.h>
#include <dirent.h>
//函数申明
int opend(const char * pathname);
void judge(char * pathname);
char * str(const char * str1,const char * str2);
void readf(const char * pathname);
DIR * dir=NULL;
//参数:pathname,opend()打开pathname路径,如果是文件调用:judge()进行文件拷贝,如果是目录调用:str()进行递归目录
int opend(const char * pathname){
dir=opendir(pathname);
if(dir==NULL)
return -1;
struct dirent * reado=NULL;
while((reado=readdir(dir))!=NULL){
char * tmps=NULL;
if(reado->d_name[0]=='.')
continue;
tmps=str(pathname,reado->d_name);
if(reado->d_type==DT_DIR){
readf(tmps);
}else{
judge(tmps);
}
if(reado==NULL)
free(tmps);
}
}
//参数:pathname,readf()对pathname进行递归,如果是文件调用:judge()进行文件拷贝,如果是目录:自调
void readf(const char * pathname){
DIR * dir=opendir(pathname);
struct dirent * reado=NULL;
while((reado=readdir(dir))!=NULL){
char * tmps=NULL;
if(reado->d_name[0]=='.')
continue;
tmps=str(pathname,reado->d_name);
if(reado->d_type==DT_DIR){
readf(tmps);
}else{
judge(tmps);
}
if(reado==NULL)
free(tmps);
}
}
//参数:pathname,pathname是文件的路径
//1:judge对pathname进行拷贝
//2:strstr()先过滤出stu.java
//3:pathname[strlen(pathname)-1]='