I'm writing a program for class, and I'm wondering about the output for a bit of code. I have some code like this:
DIR* dir = opendir(".");
struct dirent* reader;
while ((reader = readdir(dir)) != NULL)
{
//print the name of the path found by reader.
}
Now this works fine and all, but I notice that the first two listings are always:
.
..
//rest of files here
Now I'm assuming the first dot .
is simply the name of the current directory, but what is the second double-dot for? I know cd ..
lets you go up in the file hierarchy, but I have no clue why that is being output when reading the subdirectory names.
The reason I'm concerned is because I want to recursively go through all the files, but if I go through the ..
, the first directory name in there is .
, which causes a loop. So how can I avoid this?