#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
int printpath(char * path )
{
DIR *directory;
struct dirent * dir_entry;
char buffer[128];
struct stat buff;
if ((directory=opendir(path)) == NULL) {
fprintf(stderr, "%s", path);
perror(" ");
return -1;
}
while (dir_entry=readdir(directory)) {
if (!strcmp(dir_entry->d_name,".")||!strcmp(dir_entry->d_name,"..")) {
/* do nothing*/
}
else
{
sprintf(buffer,"%s/%s",path,dir_entry->d_name);
if (lstat(buffer,&buff)<0)
continue;
if(S_ISDIR(buff.st_mode))
{
printf(" \n directory -%s \n \n", buffer);
printpath(buffer);
}
else
{
printf("file name = %s path= -%s \n" ,dir_entry->d_name, path);
}
}
}
closedir(directory);
}
int main()
{
printpath("/root/util/tmp");
return 0;
}
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
int printpath(char * path )
{
DIR *directory;
struct dirent * dir_entry;
char buffer[128];
struct stat buff;
if ((directory=opendir(path)) == NULL) {
fprintf(stderr, "%s", path);
perror(" ");
return -1;
}
while (dir_entry=readdir(directory)) {
if (!strcmp(dir_entry->d_name,".")||!strcmp(dir_entry->d_name,"..")) {
/* do nothing*/
}
else
{
sprintf(buffer,"%s/%s",path,dir_entry->d_name);
if (lstat(buffer,&buff)<0)
continue;
if(S_ISDIR(buff.st_mode))
{
printf(" \n directory -%s \n \n", buffer);
printpath(buffer);
}
else
{
printf("file name = %s path= -%s \n" ,dir_entry->d_name, path);
}
}
}
closedir(directory);
}
int main()
{
printpath("/root/util/tmp");
return 0;
}