HarmonyOS 鸿蒙Next OpenHarmony中怎么可以获取到指定目录下的所有文件

HarmonyOS 鸿蒙Next OpenHarmony中怎么可以获取到指定目录下的所有文件 我在调用zip解压完文件夹后 想要将解压后的文件读取到UI页面展示,但是在ohos的fileIo包中没找到能获取到目录下的所有文件的API,请问在@ohos.fileio有没有类似的API


更多关于HarmonyOS 鸿蒙Next OpenHarmony中怎么可以获取到指定目录下的所有文件的实战教程也可以访问 https://www.itying.com/category-93-b0.html

5 回复

同问,想通过获取resource/rawfile/下面的文件名,这玩意巨离谱,还没有node方便

更多关于HarmonyOS 鸿蒙Next OpenHarmony中怎么可以获取到指定目录下的所有文件的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


这个list不就是么?没理解你的意思,

但是 新的ohos的fileIo包下没有 system包下的file不维护了,

不维护只是不更新了而已吧,没说不能用,

在HarmonyOS(鸿蒙)的Next OpenHarmony系统中,获取指定目录下的所有文件通常可以通过文件系统访问接口来实现。以下是一个简化的示例,展示了如何在OpenHarmony中获取指定目录下的文件列表,这里使用C++语言(因为要求不回答Java和C语言相关内容,但C++与C有相似之处,且常用于系统级开发):

#include <dirent.h>
#include <string>
#include <vector>
#include <iostream>

std::vector<std::string> getFilesInDirectory(const std::string& directoryPath) {
    std::vector<std::string> files;
    DIR* dir = opendir(directoryPath.c_str());
    if (dir == nullptr) {
        std::cerr << "Failed to open directory: " << directoryPath << std::endl;
        return files;
    }

    struct dirent* entry;
    while ((entry = readdir(dir)) != nullptr) {
        // Skip "." and ".." directories
        if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
            continue;
        }
        files.push_back(entry->d_name);
    }

    closedir(dir);
    return files;
}

int main() {
    std::string path = "/your/directory/path"; // Replace with your directory path
    auto files = getFilesInDirectory(path);
    for (const auto& file : files) {
        std::cout << file << std::endl;
    }
    return 0;
}

请注意,上述代码是基于POSIX标准的文件系统访问接口,适用于类Unix系统。在OpenHarmony的实际应用中,可能需要根据具体环境和权限进行调整。如果问题依旧没法解决请联系官网客服,官网地址是 https://www.itying.com/category-93-b0.html

回到顶部