Shop OBEX P1 Docs P2 Docs Learn Events
SD Card interface: Can I read names of files already on card? — Parallax Forums

SD Card interface: Can I read names of files already on card?

FlyingFishFingerFlyingFishFinger Posts: 461
edited 2008-12-08 21:22 in Propeller 1
That would be nice. I've got a device hooked to a card that generates files with random names (unpredictable, really, unless I exactly synced an RTC with the internal clock of the other device...filenames include a timestamp down to the second). I need to be able to access these files with the propeller, but as far as I can tell, the SD card object requires a known filename to be specified.
Is there a way around this?
Thanks

Rafael

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You've got to play the game.
You can't win.
You can't break even, except on a very cold day.
It doesn't get that cold.
~Laws of Thermodynamics~

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-12-08 06:14
    Finger,

    I'm not sure why you would want to name files randomly, unless, of course, you have time stamps recorded inside the files along with whatever data you record. You might what to elaborate more on what you're trying to do both on the data recording end of it and on the data accessing end of it.
  • FlyingFishFingerFlyingFishFinger Posts: 461
    edited 2008-12-08 06:21
    I can't affect the recording side. The box that generates the data is a cheap video digitizing box that takes an analog video input and turns it into mpeg files on an SD card. These are named according to the date and time the recording was started, or something like that. I have absolutely no control over them. I would like to access the raw video data, which I can do with the SD card object, but only if I know the filename. As far as I can tell there's no such thing as "Open the first file in the directory" or "list filenames".

    Rafael

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You've got to play the game.
    You can't win.
    You can't break even, except on a very cold day.
    It doesn't get that cold.
    ~Laws of Thermodynamics~
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-08 06:22
    1) Remember that the SD card routines use 8.3 (short) filenames. If your device generates long filenames, these will be "mangled" to fit uniquely in an 8.3 format.

    2) There are PUB routines in the SD card object called "opendir" and "nextfile" used to make directory listings. You could use these to either go through all the root files in directory order looking for one that matches some criteria that you specify, then open the file using its name. You'd have to go through the file list each time unless you want to save the names in an array to speed up the process next time.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-12-08 14:38
    I believe Raymans Ymodem utility already has directory listing code if you want to keep from
    re-inventing the wheel.

    http://forums.parallax.com/showthread.php?p=719452

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with a Propeller Protoboard?
    Check out: Introduction to the Proboard & Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card connected? - PropDOS
  • mcstarmcstar Posts: 144
    edited 2008-12-08 21:22
    Femto basic has a "files" command that list all the files. You should be able to get a list of files using the same method.
    here's the relevant code from Femto...

     146: ' FILES
                   if \fsrw.mount(spiDO,spiClk,spiDI,spiCS)
                      abort string("Can't mount SD card")
                   fsrw.opendir
                   b := 0
                   d := false
                   repeat while fsrw.nextfile(@f0) == 0
                      d := true
                      if b == 39
                         dsp.out(dsp#Cr)
                         b := 0
                      dsp.str(@f0)
                      repeat 13 - strsize(@f0)
                         dsp.out(" ")
                      b := b + 13
                   if d
                      dsp.out(dsp#Cr)
                   \fsrw.unmount
    
    
Sign In or Register to comment.