我只想讀取子目錄和指向子目錄的鏈接。 使用下面的代碼我讀了所有的subdirs和鏈接。確定鏈接指向的目錄條目的類型
struct dirent* de;
DIR* dir = opendir(c_str());
if (!dir) { /* error handling */ }
while (NULL != (de = readdir(dir))) {
if (de->d_type != DT_DIR && de->d_type != DT_LNK)
continue;
// Do something with subdirectory
}
但是,如何檢查鏈接是否也指向子目錄呢?我不想閱讀整個鏈接目錄來執行此操作。
爲了什麼目的,你既C和C++標籤呢? – usr2564301
您是否在尋找readlink? http://linux.die.net/man/3/readlink – mikedu95
'readlink'得到指向的東西的路徑,'stat'用於檢查它是否是一個目錄? – mindriot