Shop OBEX P1 Docs P2 Docs Learn Events
SD card file rename? — Parallax Forums

SD card file rename?

RaymanRayman Posts: 14,162
edited 2007-12-01 17:57 in Propeller 1
Anybody figured out how to rename a FAT16 file using fsrw or Femtofsrw?

It would be very convenient to have this ability right now for me...

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-01 17:05
    It can't be done without modifying fsrw or Femtofsrw and writing a special routine to do it.

    First you have to make sure there isn't a file already with the new name, then you have to
    open the file under the old name, change the directory entry, and write it back. It's not too
    different from deleting a file, but somebody has to do the work.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-12-01 17:20
    Why not do this in two steps, and I think they are already there...

    First copy the file to the new filename, then delete the old file.

    IIRC, there is an example of copy & delete in Femto.

    OBC


    EDIT: yup thought I saw it in there... These could be adapted readily..

    Copy
                     ' COPY [noparse][[/noparse]<expr>],"<file>" or COPY "<file>",[noparse][[/noparse]<expr>] or
                     ' COPY [noparse][[/noparse]<expr>],[noparse][[/noparse]<expr>] where <expr> are different
                   if spaces == quote
                      scanFileName(@f0)
                      if spaces <> ","
                         abort @syn
                      skipspaces
                      b := getAddress(",") & !$7FFF
                      ifnot fsrw.checkPresence(b)
                         abort string("No EEPROM there")
                      if \fsrw.mount(spiDO,spiClk,spiDI,spiCS) < 0
                         abort string("Can't mount SD card")
                      if \fsrw.popen(@f0,"r")
                         abort string("Can't open file")
                      if fsrw.pread(@f0,32) <> 32
                         abort string("Can't read program")
                      if \fsrw.pclose < 0
                         abort string("Error closing file")
                      \fsrw.unmount
                   else
                      a := getAddress(",") & !$7FFF
                      ifnot fsrw.checkPresence(a)
                         abort string("No EEPROM there")
                      if spaces <> ","
                         abort @syn
                      skipspaces
                      if spaces == quote
                         scanFileName(@f0)
                         if \fsrw.mount(spiDO,spiClk,spiDI,spiCS) < 0
                            abort string("Can't mount SD card")
                         if \fsrw.popen(@f0,"w")
                            abort string("Can't create file")
                         b := 0
                         if \fsrw.pclose < 0
                            abort string("Error closing file")
                         \fsrw.unmount
    
    



    Delete
                  ' DELETE " <file> "
                   if spaces <> quote
                      abort @syn
                   scanFilename(@f0)
                   if \fsrw.mount(spiDO,spiClk,spiDI,spiCS) < 0
                      abort string("Can't mount SD card")
                   if \fsrw.popen(@f0,"d")
                      abort string("Can't delete file")
                   if \fsrw.pclose < 0
                      abort string("Error deleting file")
                   \fsrw.unmount
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just getting started with Propeller?

    Propeller Cookbook

    PropDOS

    Post Edited (Oldbitcollector) : 12/1/2007 5:39:21 PM GMT
  • RaymanRayman Posts: 14,162
    edited 2007-12-01 17:38
    This may be naive, but can't one just change characters in the FAT table?· Aren't all the filenames stored there?

    Mike: Is this what you are saying?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-01 17:57
    Rayman,
    That's essentially what I'm saying. It's just that you have to do it properly with the right error checking.
Sign In or Register to comment.