I'm trying to test if a file exists with expo.
This is the expo doc : Returns If no item exists at this URI, returns { exists: false, isDirectory: false }. Else returns an object
if (this._liste.length === 0) {
let tmp =FileSystem.getInfoAsync('file://exemple.json');
if(tmp.exists === false){
alert("not found")
}
}
The File doesn't exist, I'm sure and the alert doesn't show. When I print tmp, I have a Object but when I print tmp.exist I have a undefined.
getInfoAsync is an async function therefore you cannot use it like a normal function. It returns a Promise so you either need to use await or then:
let tmp = await FileSystem.getInfoAsync('file://exemple.json');
// use tmp.exists
FileSystem.getInfoAsync('file://exemple.json').then(tmp => {
// use tmp.exists
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With