Chinaunix首页 | 论坛 | 博客
  • 博客访问: 445561
  • 博文数量: 293
  • 博客积分: 4204
  • 博客等级: 上校
  • 技术积分: 3060
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-21 10:27
个人简介

nobody

文章分类

全部博文(293)

文章存档

2014年(27)

2013年(105)

2012年(41)

2011年(109)

2010年(11)

分类:

2011-02-23 13:45:52

static unsigned int file_counter = 0;
static void get_file_list(char *path,FILE_LIST_T *list, int max_list)
{
DIR *dirp;
struct dirent *direntp;
char buf[150];
char mtd_dir[100];
struct stat statbuf;

dirp=opendir(path);
if(dirp==NULL)
{
printf("open directory %s error\n",path);
return;
}
while((direntp=readdir(dirp))!=NULL)
{

if(strcmp(direntp->d_name,".")==0 || strcmp(direntp->d_name,"..")==0)
continue;
snprintf(buf,sizeof(buf),"%s%s",path,direntp->d_name);
if(stat(buf,&statbuf)==-1)
{
printf("stat failed on %s\n",buf);
continue;
}
/*here we process only directory®ular file items,which means that  link/device/socket/fifo files are ignored*/
if(S_ISDIR(statbuf.st_mode))/*the item is a directory */
{
snprintf(mtd_dir,sizeof(mtd_dir),"%s%s","mkdir /flash/",buf+strlen(LS_PATH));
system(mtd_dir);/*this will makes the system unstable!*/
strcat(buf,"/");
get_file_list(buf,list,max_list);
}
else if(S_ISREG(statbuf.st_mode))/*the item is a regular file*/
{
list[file_counter].name = (char *)malloc(LS_FILE_NAME_LEN);
if (list[file_counter].name  == NULL)
{
printf("ls malloc failed\n");
return;
}
snprintf(list[file_counter].name,LS_FILE_NAME_LEN,"%s%s",path+strlen(LS_PATH),direntp->d_name);
list[file_counter].file_size = statbuf.st_size;
fs_total_size+= list[file_counter].file_size;
if(++file_counter>=max_list) 
break;
}
}
closedir(dirp);
}
类似的操作可以参考busybox中的recursive_action.c  recursive_action()。
阅读(1793) | 评论(0) | 转发(0) |
0

上一篇:获取文件size

下一篇:使用wpa_supplicant

给主人留下些什么吧!~~