REQ: FileExists() for all platforms

Monkey Forums/Monkey Programming/REQ: FileExists() for all platforms

Nobuyuki(Posted 2014) [#1]
I want to be able to check if a file in my data folder exists without having to actually use LoadString() on the file. In the os module, FileType() should be able to tell me what I need to know (although iirc, I was never able to get it to work correctly on my XP machine), but this is specific to desktop and cpp targets. I want to be able to check if a file exists on all targets, preferably, at least files which all targets can load, before attempting to load the entire file.

The reason is that synchronous access causes hiccups in my loading screen when cycling through resources -- the routine calls LoadString() sequentially in a loop on pre-determined filenames until LoadString() returns a blank. The metadata for these are loaded synchronously, but there are other resources associated with the metadata (think image atlases and sound banks) that can (and are) loaded asynchronously. If I'm able to check that the files exist first, I can move the actual LoadString() calls to OnLoadImageComplete(), giving a much more accurate reading of the loading progress to the user because metadata parsing would occur as assets are loaded instead of all at the beginning. This also gives the render thread a chance to update the progress instead of one big hiccup at the beginning.

If I were to change all LoadString() calls to asynchronous DataBuffers, this may alleviate my problem slightly, but it would still leave the problem of waiting for each test to come back to check for Nulls before proceeding to load associated images. While waiting for this information, the loader is completely oblivious to how far along it actually is in the process, and isn't able to give a reliable percentage completed value because it doesn't know how many resources it has to load yet....


EDIT: Solved, see below!


Markus(Posted 2014) [#2]
i believe if open fail you can test return value with =null
a small function for FileExists


nikoniko(Posted 2014) [#3]
What is target this code from monkey doc works incorrect ?


filetype() function is based on stat() POSIX function. except Android and Win8/WP8 targets where it uses SDK file's methods


Nobuyuki(Posted 2014) [#4]
Thanks niko, I didn't realize that namespace existed. I'll look into it.


Nobuyuki(Posted 2014) [#5]
It works! Thanks again. I'm surprised I missed this.