How to check if file exists

I tried to check if a file exist inside Data directory on Android. Y tried using two different ways, using stat and using readdir.

Both ways return a weird exception and no results, even when i can see in the debug that is working.

For example:
Filesystem.readdir({

            path: '/',

directory: Directory.Data

        }).then((ret)=>{

console.log(“Directorio”);

console.log(ret);

returns
Msg: Directorio
Line 2 - Msg: [object Object]
Line 2 - Msg: Uncaught (in promise) TypeError: r is not a function

And

Filesystem.stat(getUriOptions);

algo gets an uncaught internal exception and can not get the result object.

Thanks

The error happens because Capacitor expects relative paths without a leading slash and the promises must be handled correctly. Use Filesystem.stat with the file name and Directory.Data, and await the result. If the file exists, it returns info; if not, it throws an error you can catch.