R nt list directory recursive
R nt list directory recursive
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;
}