1. 程式人生 > >ndk讀取資料夾下的檔案列表

ndk讀取資料夾下的檔案列表

    char *dir_path = "/mnt";
    DIR *dir = opendir(dir_path);

    if (dir == NULL) {
        LOGD("open dir error!");
        return -1;
    }

    struct dirent *ptr;
    char buf[100];
    char link_name[100];
    while ((ptr = readdir(dir)) != NULL) {
        switch (ptr->d_type) {
            case
DT_LNK: sprintf(link_name, "%s/%s\0", dir_path, ptr->d_name); readlink(link_name, buf, sizeof(buf)); LOGD("type: %d name:%s/%s -> %s", ptr->d_type, dir_path, ptr->d_name, buf); break; default: LOGD("type: %d name:%s/%s"
, ptr->d_type, dir_path, ptr->d_name); break; } } closedir(dir);