int main(int argc, const char *argv[])
{
char tar_path[200] = {0};
char org_path[200] = {0};
DIR* dp = opendir(argv[1]);
if(dp==NULL)
{
perror("opendir");
return -1;
}
while(1)
{
struct dirent* file = readdir(dp);
if(file==NULL){break;}
if(strcmp(file->d_name,".")==0 || strcmp(file->d_name,"..")==0){continue;}
// chdir(argv[1]);
strcpy(tar_path,argv[1]);
strcat(tar_path,"/");
strcat(tar_path,file->d_name);
int rfd = open(tar_path,O_RDONLY);
printf("%s\n",tar_path);
// chdir("..");
// chdir(argv[2]);
strcpy(org_path,argv[2]);
strcat(org_path,"/");
strcat(org_path,file->d_name);
int wfd = open(org_path,O_WRONLY | O_CREAT | O_TRUNC,0666);
printf("%s\n",org_path);
// chdir("..");
while(1)
{
char buf[16] = {0};
int res = read(rfd,buf,15);
if(res==0){break;}
write(wfd,buf,strlen(buf));
}
}
return 0;
}
7.17号作业
最新推荐文章于 2024-07-22 15:19:55 发布