Shop OBEX P1 Docs P2 Docs Learn Events
Kye's SD2.0_FATengine - how to check if a file exists? — Parallax Forums

Kye's SD2.0_FATengine - how to check if a file exists?

MicrocontrolledMicrocontrolled Posts: 2,461
edited 2010-09-21 16:16 in Propeller 1
I've recently made the switch from the ever popular fsrw SD program to Kye's driver because I needed multiple directory support. I made my program I'm working over switch perfectly, except that wheras with fsrw I could have the PROGRAM see if the file exists by calling popen and getting the return value, FATengine returns a hard-to-read abort string. I'm using Raymans 4.3" LCD, and it goes black when the FATengine aborts, I'm not sure why. I went in the program and changed the "abort @filedoesntexist" with "return 3" and set up a test program with the same results. If I can only read I file I know is there, this program will not be of much use and I'll go back to the old fsrw. I could just be missing something as there are many functions in the FATengine program. Is there a function for checking the availibility of a file? If so can someone direct me to it?

ANY help is appreciated, thanks!

Micro

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-21 13:12
    There's only a limited number of things that can go wrong when you try to open a file. Just use the "catch" operator (\) to catch the abort when you try to open your file and check for any non-zero error or the specific constant for the error you expect.

    \engine.fileOpen(@name,mode)
    if engine.checkErrorNumber == engine#File_Not_Found
    ' file not found error occurred
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-09-21 13:35
    Thanks, now it doesn't freeze, but it also returns the same value wether the file exists or it doesn't. The "if engine.checkErrorNumber == engine#File_Not_Found" doesn't ever trigger.
  • KyeKye Posts: 2,200
    edited 2010-09-21 16:16
    ... The error will be raised if the abort happens. If you get the file not found error string then the file not found error will be returned by the checkErrorNumber function.

    Also... try
    variableName := \engine.fileOpen(@name,mode)

    vs
    \engine.fileOpen(@name,mode)

    ... I'd had PROBLEMS!!! with SPIN when you don't do that.

    Note that the checkErrorNumber function returns the most recent error only and is cleared after you read it.
Sign In or Register to comment.