|
Hi all
I'm new this forum and have just discovered eLua for mBed :-)
I have a question regarding the following code, which I would like to use to assess if a file is present on the mBed built-in flash-drive (/SEMI/):
pathandfile = "/semi/1.txt"
file = io.open(pathandfile, 'r')
if file == nil then
print("File not found")
io.close()
else
print("File found")
file:close()
end
When I execute the code, it always returns "File Found", even if the file '1.txt' is not present. To my understanding, io.open should return a nil when there is an issue opening a file (e.g. it does not exist), however, here it doesn't seem to be the case.
If I remove the filename in the 'pathandfile' string altogether (e.g. pathandfile = "/semi/"), then I get a File not Found, however pathandfile = "/semi/blah.txt" when blah.txt doesn't exist still returns 'File found'
Any ideas what I'm doing wrong here?
Regards
Jim
|