是的,Linux中的opendir()函数可以递归地打开目录
#include <dirent.h> #include <stdio.h> int main() { DIR *dir; struct dirent *entry; const char *path = "."; // 当前目录 dir = opendir(path); if (dir == NULL) { perror("Failed to open directory"); return 1; } while ((entry = readdir(dir)) != NULL) { printf("%s\n", entry->d_name); } closedir(dir); return 0; } 在这个示例中,我们使用.表示当前目录。如果你想递归地打开一个子目录,可以将.替换为子目录的路径。例如:
const char *path = "./subdir"; // 子目录