无法在react-native-fs中获取文件

7lrncoxx  于 2023-10-22  发布在  React
关注(0)|答案(1)|浏览(114)

我使用react-native-fs在react-native-socket应用程序读取设备的内部存储,但它只是阅读文件夹,而不是文件
我在AVD和物理设备上都试过了,react-native-fs的每个API,比如DownloadDirectoryPath,ExternalDirectoryPath,它只读取它们内部的文件夹。我想阅读文件夹以及文件,无论是什么文件,如pdf,音频,txt,视频等。

const readFiles = async () => {
try {
const downloadFolderPath = RNFS.DownloadDirectoryPath
const files = await RNFS.readDir(downloadFolderPath);
console.log(files)

}
catch{
console.log('error occur')
}
}

输出中的此代码的输出仅获取文件夹而不是文件

[{"ctime": null, "isDirectory": [Function isDirectory], "isFile": [Function isFile], "mtime": 2023-07-10T09:20:27.000Z, "name": "indownload", "path": "/storage/emulated/0/Download/indownload", "size": 4096}]
mu0hgdu0

mu0hgdu01#

试试这个:

const readFiles = async () => {
    try {
        const downloadFolderPath = RNFS.DownloadDirectoryPath
        const files = await RNFS.readDir(downloadFolderPath);
        files.forEach(f => console.log(f.name))
    } catch {
        console.log('error occur')
    }
}

相关问题