osx - "Double dot" directory name in C? -
I am writing a program for the class, and I'm thinking about the output for a little code. I have such a code:
DIR * dir = opendir ("."); Struct dirent * Reader; While ((reader = readdir (dir))! = NULL) {// Print the name of the path found by the reader. } Now it is fine and all works, but I have noticed that the first two entries are always:
. .. // Here rest files Now I'm assuming the first dot . is just the name of the current directory, but what is the second double? I know cd .. you have to go up in the file hierarchy, but I have no clue why this output is being made while reading subdirectory names me The reason for being worried is that I want to go to all the files continuously, but if I pass through .. , then the first directory name of it . , which causes a loop, how can I avoid it?
.. is the root directory unless you are on file system root , Then it is similar to the root directory. Actually you want to see that your dir variable or or .. . If so, then you leave that directory. You can get it by checking the check in your while loop or by filtering those two directories from your array of directories. Oh, make sure that you do not accidentally leave directories that start with . , because they are still valid directories, make sure the entire directory name is . or .. .
Comments
Post a Comment