Shop OBEX P1 Docs P2 Docs Learn Events
Can KyeFAT open files by filenumber? — Parallax Forums

Can KyeFAT open files by filenumber?

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2012-08-30 09:25 in Propeller 1
I'm fighting with what should be a simple routine. I'm attempting to open files by file number (a simple trick in fsrw) using the KyeFAT driver.
PUB openNextFile | i

    sd.listEntries("W")
    repeat i from 0 to fileNumber
        repeat while(buffer := sd.listEntries("N"))      
           str.copy(buffer,@filename)
           str.trimstring(@filename)
        i++
    'sd.openfile( @filename, "r")   

The idea here is to read the directory up to the "fileNumber", then open that file. Increasing/Decreasing "fileNumber" and re-running the routine should allow me to switch to the next file or the previous.

Can someone see where I'm going wrong here?

Thanks

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2012-08-30 09:25
    Overthinking it. Here's a working solution should someone turn this thread up later.
    PUB openNextFile | i,data
    
        sd.listEntries("W")
        repeat fileNumber
             data := sd.listEntries("N")
                     
        data := sd.listEntries("N")
        trimString(data)
    
        sd.openfile( data, "r")           
    
    PUB trimString(characters)
    
      result := ignoreSpace(characters)
      characters := (result + ((strsize(result) - 1) #> 0))
    
      repeat
        case byte[characters]
          8 .. 13, 32, 127: byte[characters--] := 0
          other: quit
    PRI ignoreSpace(characters) ' 4 Stack Longs
    
      result := characters
      repeat strsize(characters--)
        case byte[++characters]
          8 .. 13, 32, 127:
          other: return characters
    
Sign In or Register to comment.