naveen
naveen

Reputation: 11

unable to fetch files in react-native-fs

I am using react-native-fs in react-native-cli app to read internal storage of device but it is only reading folders not files

I have tried on both AVD and physical device and every api of react-native-fs like DownloadDirectoryPath, ExternalStorageDirectoryPath it only reads folders inside them. I want to read folders as well as files whatever file it is like pdf, audio, txt, video etc.

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

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

output of this code in output only getting folders not files

[{"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}]

Upvotes: 0

Views: 209

Answers (1)

Luzivog
Luzivog

Reputation: 11

Try this:

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')
    }
}

Upvotes: 0

Related Questions