Linux 程序设计学习笔记----文件管理实例应用(二)

2014-11-23 22:00:03 · 作者: · 浏览: 54
eof(struct fnode));
if(NULL==temp)
{
perror("malloc");exit(EXIT_FAILURE);
}
temp->next=NULL;
memset(temp->name,'\0',NAME_SIZE);
memcpy(temp->name,argv[i],strlen(argv[i]));
linklist=insert_list(temp,linklist);
output_info(linklist);//output information of the file
}
else if(S_ISDIR(stat_info.st_mode))
{
char buf[NAME_SIZE];
getcwd(buf,128);

DIR *dirp=NULL;
dirp=opendir(argv[i]);
if(NULL==dirp)
{
perror("opendir");exit(EXIT_FAILURE);
}


struct dirent *entp=NULL;

while(entp=readdir(dirp))
{
struct fnode *temp=(struct fnode *)malloc(sizeof(struct fnode));
if(NULL==temp)
{
perror("malloc");exit(EXIT_FAILURE);
}
temp->next=NULL;
memset(temp->name,'\0',NAME_SIZE);
memcpy(temp->name,entp->d_name,strlen(entp->d_name));
linklist=insert_list(temp,linklist);
}
chdir(argv[i]);//change the current dirctory
close(dirp);
output_info(linklist);
chdir(buf);
}
free_list(linklist);
}
return 1;
}


Linux 程序设计学习笔记----文件管理实例应用