opendir 取目录下的子节点

来源:互联网 发布:vm12安装mac os win10 编辑:程序博客网 时间:2024/06/04 18:28

#include <iostream>

#include <assert.h>

#include <dirent.h>


using std::cout;

using std::cin;

using std::endl;

using std::string;


int main()

{

    const size_t buf_size = 1024;

    char dirbuf[buf_size];

    assert(getcwd(dirbuf, buf_size) != NULL);

    DIR* d = opendir(dirbuf);

    assert(d != NULL);

    struct dirent* entry;

    while ((entry = readdir(d)) != NULL) {

        cout << entry->d_reclen << endl;

        cout << entry->d_type << endl;

        cout << entry->d_name << endl;

    }

    return 0;

}


0 0