Announcement

Collapse
No announcement yet.

Why does this cause a blank file on the SD card that cannot be deleted?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why does this cause a blank file on the SD card that cannot be deleted?

    Why does this cause a blank file on the SD card that cannot be deleted and then the card must be reformatted?

    Code:
    #platform "uVGA-III"
    
    #inherit "4DGL_16bitColours.fnc"
    
    var handle;
    var res;
    var filename[20];
    var inc;
    
    func main()
    
        gfx_ScreenMode(LANDSCAPE);
        txt_Set(TEXT_COLOUR, GRAY);
        txt_MoveCursor(1,1);
    
        print("H") ;
    
        pause(1500);
    
        inc := 7;
        to(filename); putstr("LOG");
        to(APPEND); print(inc);
        to(APPEND); putstr(".txt");
    
    
        handle := file_Mount();
        if (file_Exists(filename))
            txt_MoveCursor(2,1);
            print("EXIST  ", [STR]filename);
            handle := file_Open(filename, 'a');
            file_PutC('A',handle);
            res := file_Close(handle);
        else
            txt_MoveCursor(2,1);
            print("DOESNT EXIST  ", [STR]filename);
    
            handle := file_Open(filename, 'a');
            file_PutC('C',handle);
            res := file_Close(handle);
        endif
    
        pause(8000);
        gfx_Cls();
    
    
        repeat                      // maybe replace
        forever                     // this as well
    
    endfunc

  • #2
    The inputs to file_Exists, file_Open, etc. are string pointers, if you use a constant filename that happens automatically for you, otherwise you need to include it.

    so try accessing the file using

    file_Exists(str_Ptr(filename))
    file_Open(str_Ptr(filename), 'a')
    etc.

    Whilst it is fine to 'throw away' the result to file_Mount(), it would be a good idea to check it to make sure the mound worked.

    The way your code is it will create a garbage filename on the uSD. Most garbage filenames need a format to remove them.
    Mark

    Comment

    Working...
    X