I am trying to read the device filesystem using react-native-fs. The code works when i console.log the contents directly but result array is always empty. what am I doing wrong?
here is my function :
getFiles = async (dir, result) => {
let contents = await RNFS.readDir(dir);
if(contents.length > 0 ){
for (let i = 0; i < contents.length; i++) {
if ( contents[i].isFile() ) {
result.push(contents[i])
}
else if (contents[i].isDirectory()) {
const newPath = dir + '/' + content[i].name;
await getFiles(newPath,result)
}
}
}
}