opendir()
、readdir()
和 closedir()
函数实现。这些函数定义在 ` 头文件中。以下是一个简单的示例代码:,,
`c,#include,#include,,void list_directory(const char *path) {, struct dirent *entry;, DIR *dp = opendir(path);,, if (dp == NULL) {, perror("opendir");, return;, },, while ((entry = readdir(dp))) {, printf("%s\n", entry->d_name);, },, closedir(dp);,},,int main() {, const char *path = "."; // 当前目录, list_directory(path);, return 0;,},
``,,这段代码会列出指定路径下的所有文件和子目录的名称。Powered By Z-BlogPHP 1.7.3