#include
#include
#include
#include
void show_files(char *path_name)
{
struct stat file_stat;
DIR *pdir_name = NULL;
struct dirent *pdir_subname = NULL;
char filename_buf[1024] = { 0 };
if(0 == lstat(path_name,&file_stat))
{
if(S_ISREG(file_stat.st_mode))
{
printf("reguler file is %s!
",path_name);
}
else if(S_ISDIR(file_stat.st_mode))
{
printf("dir is %s
",path_name);
if(NULL == (pdir_name = opendir(path_name)))
{
exit(0);
}
while((pdir_subname = readdir(pdir_name)) != NULL)
{
if(pdir_subname->d_name[0] == '.')
{
continue;
}
snprintf(filename_buf,sizeof(filename_buf),"%s/%s",path_name,pdir_subname->d_name);
show_files(filename_buf);
}
}
}
return;
}
void main(int argc , char *argv[])
{
struct stat file_stat;
if(argc < 2)
{
printf("parameter error! FILE %s,LINE %d
",__FILE__,__LINE__);
exit(0);
}
if(0 != lstat(argv[1],&file_stat))
{
printf("parameter error! FILE %s,LINE %d
",__FILE__,__LINE__);
}
else
{
if(S_ISREG(file_stat.st_mode))
{
printf("%s is a reguler file!
",argv[1]);
}
else if(S_ISDIR(file_stat.st_mode))
{
show_files(argv[1]);
}
else
{
printf("%s is other type file",argv[1]);
}
}
exit(0);
}