我試圖使用dirent.h顯示所有在Windows路徑的所有文件和子目錄,這是我到目前爲止的代碼:爲什麼這些點出現(C++ dirent.h)
void print_dir(char* path, char* subdir)
{
char full_path[MAX_PATH];
concat_path(full_path, path, subdir);
DIR *dir;
struct dirent *ent;
if ((dir = opendir (full_path)) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir(dir)) != NULL) {
if(is_dir(full_path, ent->d_name)){
printf ("DIR %s\\%s\n",full_path, ent->d_name);
print_dir(full_path, ent->d_name);
}
else{
printf ("%s\\%s\n",full_path, ent->d_name);
}
}
closedir (dir);
} else {
/* could not open directory */
perror ("");
}
}
我在一個目錄D:\ test上試了一下,它有兩個子目錄,每個子目錄中都有一個文件,並且該函數陷入無限遞歸,並無限地顯示\.\.\.\.\.\.
。如果我提出一個條件來檢查名稱是否是「。」。或「..」,如果不做任何事情,它都按計劃運作。那麼這些點是什麼?
http://stackoverflow.com/questions/8411931/what-does-dot-and-dotdot-means – user2120666
你能告訴我,如果檢查點和dotdot的名稱是一個很好的做法,或者我應該做別的嗎? – user2419750