1

I was trying to list all the files in a folder using rn fetch blob in react native. When i tried to list it i am getting an error saying

[Error: Attempt to get length of null array]

here is the below code I have tried to list the files.

 try {
        var TRACK_FOLDER = RNFetchBlob.fs.dirs.DownloadDir + '/BlabberApp/';
        let files = await RNFetchBlob.fs.ls(TRACK_FOLDER)
        console.log(files);
      } catch (error) {
        console.log(error);
      }

Its working perfectly in system emulator and when i tested in real devices its force closing and throwing this error. I am pretty sure that i gave given storage permission for this but still I am getting this error.

Any help would be appreciable.

Thanks in advance :)

Thomas James
  • 187
  • 2
  • 16

2 Answers2

1

use this code ,I am using this to get the name of files in that specified folder and TRACK_FOLDER is path of the folder-

RNFetchBlob.fs.ls(TRACK_FOLDER).then(files => {
  console.log(files);
 
}).catch(error => console.log(error))
priyanka
  • 171
  • 2
  • 12
0

Usually, this is a Storage Permission Error: You need to ask permission.

Paulo Amf
  • 360
  • 3
  • 14