#include <stdio.h>
#include <sys/stat.h>
#include <dirent.h>
#include <stdlib.h>
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!\n",path_name);
}
else if(S_ISDIR(file_stat.st_mode))
{
printf("dir is %s \n",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\n",__FILE__,__LINE__);
exit(0);
}
if(0 != lstat(argv[1],&file_stat))
{
printf("parameter error! FILE %s,LINE %d\n",__FILE__,__LINE__);
}
else
{
if(S_ISREG(file_stat.st_mode))
{
printf("%s is a reguler file!\n",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);
}
#include <sys/stat.h>
#include <dirent.h>
#include <stdlib.h>
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!\n",path_name);
}
else if(S_ISDIR(file_stat.st_mode))
{
printf("dir is %s \n",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\n",__FILE__,__LINE__);
exit(0);
}
if(0 != lstat(argv[1],&file_stat))
{
printf("parameter error! FILE %s,LINE %d\n",__FILE__,__LINE__);
}
else
{
if(S_ISREG(file_stat.st_mode))
{
printf("%s is a reguler file!\n",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);
}