#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <dirent.h>
void isfile(char *name);
void read_dir(char *dir)
{
DIR *dp;
struct dirent *sdp;
char path[256];
dp=opendir(dir);
if(dp==NULL)
{
perror("opendir error");
return;
}
while((sdp=readdir(dp))!=NULL)
{
if(strcmp(sdp->d_name,".")==0||strcmp(sdp->d_name,"..")==0)
{
continue;
}
sprintf(path,"%s/%s",dir,sdp->d_name);
isfile(path);
}
closedir(dp);
return;
}
void isfile(char *name)
{
int ret=0;
struct stat sb;
ret=stat(name,&sb);
if(ret==-1)
{
perror("stat error");
return;
}
if(S_ISDIR(sb.st_mode))
{
read_dir(name);
}
printf("%-20s\t\t%-ld\n",name,sb.st_size);
return;
}
int main(int argc,char *argv[])
{
if(argc==1)
isfile(".");
else
isfile(argv[1]);
return 0;
}