I have a program that prints out all the directories listed inside a specific directory, by checking that d_type == DT_DIR
the program works, but also prints out the parent directory ..
and the curent directory .
I tried to set an if statement to check that d_name != ".." or "."
, but it still printed parent and current directory
here is my code with the added if statement to
directory = opendir("/home/user/adirectory");
if(directory != NULL)
{
while(entry = readdir(directory)) {
if(entry->d_type == DT_DIR && entry->d_name != ".." && entry->d_name != ".")
printf("%s\n", entry->d_name);
}
}
unfortunately this is the output, where dir2 is a directory inside adirectory
..
dir2
.
I would like instead an output that only shows this directory without dot or two dots
dir2