0% found this document useful (0 votes)
10 views1 page

R nt list directory recursive

Uploaded by

ola.alao007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

R nt list directory recursive

Uploaded by

ola.alao007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

-R

nt list_directory_recursive(char *path)
{
struct dirent *entry;
DIR *dir = opendir(path);
char *new_path;
struct dirent *entry2;

if (!dir)
return 84;
my_putstr(path);
my_putstr(":");
my_putchar('\n');
while ((entry = readdir(dir)) != NULL){
if (entry->d_name[0] == '.')
continue;
if (entry->d_type == DT_DIR) {
entry2 = readdir(dir);
if (entry2->d_type == DT_REG){
if (entry2->d_name[0] == '.')
continue;
else{
my_putstr(entry2->d_name);
my_putchar('\n'); }
}
new_path = malloc(sizeof(strlen(path) + strlen(entry->d_name) + 2));
strcpy(new_path, path);
strcat(new_path, "/");
strcat(new_path, entry->d_name);
my_putstr(entry->d_name);
my_putchar('\n');
list_directory_recursive(new_path);
free(new_path);
}
}
closedir(dir);
}
int main(int argc, char *argv[]) {
if (argc < 2) {
list_directory_recursive(".");
}else{
for (int i = 1; i < argc; i++) {
list_directory_recursive(argv[i]);
}
}
return 0;
}

You might also like