How to use FileSystem.getInfoAsync ?

I’m trying to test if a file exist with expo.

 let tmp =FileSystem.getInfoAsync('file://example.json');

                if(tmp.exists === false){
                    alert("not found")

When I print tmp if have an Object but when I print tmp.exists I have undefined.

Hey @tomgalanx,

Thanks for asking this, as the documentation isn’t super clear. So first off, getInfoAsync returns a Promise, and I suggest using the async/await syntax. Plus, you need to preface the file location with FileSystem.documentDirectory, read about that here.

You can take a look at this snack example for the exact code :+1:

Thanks again!

Edit: opened up a GH issue, I’ll work on this soon

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.