![]() |
Forum Index : Microcontroller and PC projects : Check for File existence on SD Card
Author | Message | ||||
atmega8![]() Guru ![]() Joined: 19/11/2013 Location: GermanyPosts: 724 |
Hi, how to Check for File existence on SD Card in MM+ ? Any idea? Thx |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3288 |
Use OPTION ERROR thus: Option ERROR CONTINUE
Open "MYFILE.EXT" For INPUT As #1 If MM.Errno = 0 Then PRINT "File exists" CLOSE #1 ELSE PRINT "File does not exist" CLOSE Option ERROR ABORT Geoff Geoff Graham - http://geoffg.net |
||||
atmega8![]() Guru ![]() Joined: 19/11/2013 Location: GermanyPosts: 724 |
Hello Geoff, ah, the environment variable makes It possible, thats the trick ![]() Thank you very much Geoff. I can test this not before tomorrow evening, so one more Question: Is it relevant to check mm.errno BEFORE closing the file handle with close #1 ? Atmega8 |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3288 |
Yes, if you check it after closing the file it will report on the success (or not) of the close. Geoff Graham - http://geoffg.net |
||||
MMAndy Regular Member ![]() Joined: 16/07/2015 Location: United StatesPosts: 91 |
Ok, I found OPTION ERROR CONTINUE/ABORT in the advanced MM+ manual. ![]() I wish there was a similar command for the normal errors in MM+ so I could make a GPIO scanner or OPTION LIST command for the Explore 64. ![]() |
||||
kiiid Guru ![]() Joined: 11/05/2013 Location: United KingdomPosts: 671 |
This actually reminds me to ask Geoff about the possibility for this idea: How about by executing a certain command MMbasic checks the entire program for syntax or other errors? This is very useful in large programs with many branches where a bug might exist hidden within some rarely executing branch. A compiler can easily pick these things during compilation, but with MMbasic such bugs can only be found when the program actually start executing the branch. Basically this functionality only needs MMBasic to scan the whole program linearly without executing it, and verify that all keywords and subs/functions are known and defined, as well as the variables. Does it sound like something possible? http://rittle.org -------------- |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4040 |
I thought it already did that?! Although... the recent ELSE END SUB posts suggests it has problems. John |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3288 |
That is an interesting idea and needs some thought... a bit like lint (for C). Correct keyword checking would be easy, less easy would be valid pin numbers, etc. Some other things like correct syntax for IF..THEN..ELSE could also be tricky. I guess that about one fifth of MMBasic is error checking but it is still a difficult subject as there are so many errors that can be made and it is easy for the interpreter to stumble off into the darkness and produce some illogical response. Geoff Geoff Graham - http://geoffg.net |
||||
kiiid Guru ![]() Joined: 11/05/2013 Location: United KingdomPosts: 671 |
Thanks Geoff. I think it is worth the shot for a command like CHECK or VERIFY, something else like that, even if unable to pick every possible error in the beginning, but at least some of them. Typical examples of mistakes (actually happened to me) may include a variable being defined as one type, but used as another, or mistyped function or variable names. More advanced things like validity of pin numbers, structures, etc... maybe in the future. In order to get those, the interpreter will have to do speculative execution, without actually executing anything. That is a much more complex matter, still not impossible, but even without it such functionality can be very helpful in development. http://rittle.org -------------- |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4040 |
It would be handy if the extra code to do it was in the PC version so flash isn't impacted - and besides it would be good to be able to thoroughly check the code before even sending across to a 'mite. John |
||||
CircuitGizmos![]() Guru ![]() Joined: 08/09/2011 Location: United StatesPosts: 1427 |
That. A check in MMEdit would be spectacular. Perhaps it could be a call to an external program? Micromites and Maximites! - Beginning Maximite |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6274 |
Checking code on the PC without all the external hardware attached would be limited. Using OPTION EXPLICIT helps catch typos. MMEdit's format option helps catch misformed loops etc. MMEdit's Variable report helps catch a few more potential errors. I have often considered a code verifier in MMEdit but it would be difficult to keep up with the ever increasing number of versions of MM Basic. MMEdit already has the ability to call an external program so if anyone is interested in providing the program... Jim VK7JH MMedit |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4040 |
I think speculative execution is rather more than was envisaged - which was to catch clearly wrong things like ELSE END SUB It might be useful for MMBasic to have a statement that a program can have (I suppose at the front) saying which kind of CPU(s) and features (I/O, min RAM size, MMBasic features - apply more thought here!) it uses so that an attempt to load it onto the wrong board can be instantly rejected with a useful error message. I'm thinking if it needs 2 SPIs and 3 UARTs (or whatever) and big arrays then it may be helpful for it to say so. John |
||||
kiiid Guru ![]() Joined: 11/05/2013 Location: United KingdomPosts: 671 |
In an interpreted environment such as MMbasic, OPTION EXPLICIT will catch something ONLY if the execution thread reach the bug. For example, if I have a loop for one million times with two branches, one executing 999999 times, and the other only once (imagine something serious - activating fire alarm for example), and my bug is hidden within the second one, it will remain hidden in 999999 times. That could be the difference between a product released with or without a bug in the software, and acting or not properly in a critical situation. http://rittle.org -------------- |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |