Check if file exists

So I have 2 methods of finding out if a file exists. They are both really slow, i’d assume the second method would be faster but is actually even slower. is there some way to just basically see if a file is there without having to load the actual content of the file into memory?

 local path = system.pathForFile( filepath, system.DocumentsDirectory )  
 local myFile = io.open( path, "r" )   
 io.close(myFile);  

local path = system.pathForFile( filepath, system.DocumentsDirectory ) local myFile = io.type(path); [import]uid: 6317 topic_id: 2324 reply_id: 302324[/import]

This thread essentially deals with the same issue:
https://developer.anscamobile.com/forum/2010/09/21/there-function-obtain-file-directory-listing

I posted a pointer to a small library that gives you a directory listing where you could easily check for a file’s existence:
http://developer.anscamobile.com/code/coronasystemdirectoryfilenameslua

It should also take care of your speed requirement as after the directory listing is read, a file-existence check is a lua-table lookup.

-Frank. [import]uid: 8093 topic_id: 2324 reply_id: 7143[/import]

i tried using this code block and the downloaded source file to get the directory listing. it works beautifully on simulator, but just halts my app from loading on device. Have oyu tried on actual device with 4.1? [import]uid: 6317 topic_id: 2324 reply_id: 7157[/import]

@FrankS: I tried to grab your code at:

http://developer.anscamobile.com/code/coronasystemdirectoryfilenameslua

but I get a message saying that access is denied and suggesting I become a subscriber. I already am a subscriber so I wonder if the URL is perhaps incorrect? [import]uid: 11045 topic_id: 2324 reply_id: 34351[/import]

*If* all you’re dealing with is image files, another imperfect workaround to check for a file’s existence is to check if display.newImage(path) is nil. Would be really nice to have a normal fileExists() function though… [import]uid: 10284 topic_id: 2324 reply_id: 36905[/import]