OpSys Spring 2006 - HW2 FAQ

Click on a question to expand it (for the details).
Click on the question title again to hide the details.

+ ., .. and readdir()

Question:

How do I avoid handling . and .. when processing a directory?


Answer:

Each time you read a directory entry (using readdir()) simply compare the name to "." and to "..":

  dp = readdir(dirp);
  if (strcmp(dp->d_name,".")==0) 
    ...

It's best to avoid making assumptions about whether readdir will always give you "." and ".." as the first two entries - this would not be portable code!