Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Teensy 3.6 SdFat access file creation date and time

  1. #1
    Senior Member
    Join Date
    Jan 2014
    Posts
    152

    Teensy 3.6 SdFat access file creation date and time

    I am able to write files with the proper date and time put into the directory.
    I am able to report the date and time on Serial monitor calling root.ls(LS_R | LS_DATE | LS_SIZE);
    I don't want to print the date to the serial monitor; rather, I need to access the data and display in on an LCD.

    root.ls is found in SdFile::ls which uses p->lastWriteDate and p->lastWriteTime

    Anybody have a simple way of doing this?

    thanks,

    Richard

  2. #2
    Senior Member
    Join Date
    May 2017
    Posts
    208
    I wish I had an answer because I think in about 2 weeks time I will want to do the same thing. Would redirecting the stream work on the Teensy?
    https://stackoverflow.com/questions/...sole-to-string

  3. #3
    Senior Member
    Join Date
    Jan 2014
    Posts
    152
    This might be okay, I hesitate though.
    These attributes are stored in the directory and not with the file. The library file SdFile.c contains the ls command which handles the print.
    It would be trivial to alter this library but that would be shortsighted.
    Thus, this code would need to be recreated passing back the strings as opposed to sending the strings to Serial.print().

    I was hoping that someone had already done this.

  4. #4
    Senior Member
    Join Date
    May 2017
    Posts
    208
    Looking at the library docs, there are two ls() variants that you provide a pointer to a stream. The exact details on use are not clear to me, but I would start there.

    Code:
    void FatFileSystem::ls 
    (
    print_t * 
    pr, 
    
    
    uint8_t 
    flags = 0 
    
    )
    
    
    inline 
    List the directory contents of the volume working directory.
    Parameters
    [in]
    pr
    Print stream for list.
    [in]
    flags
    The inclusive OR of
    LS_DATE - Print file modification date
    LS_SIZE - Print file size.
    LS_R - Recursive list of subdirectories. 
    ◆ ls() [4/4]
    void FatFileSystem::ls 
    (
    print_t * 
    pr, 
    
    
    const char * 
    path, 
    
    
    uint8_t 
    flags 
    
    )
    
    
    inline 
    List the directory contents of a directory.
    Parameters
    [in]
    pr
    Print stream for list.
    [in]
    path
    directory to list.
    [in]
    flags
    The inclusive OR of
    LS_DATE - Print file modification date
    LS_SIZE - Print file size.
    LS_R - Recursive list of subdirectories.

  5. #5
    Senior Member
    Join Date
    May 2017
    Posts
    208
    The example called OpenNext seems to be the way things are done, even in the ls() method. I wished to capture the file name and file size and I think this code is going to work. Ignore the fake floppy format part.

    Code:
    void mk_fake_fs2(){    // make a fake filesystem 180k floppy
    int i;
    
    SdFile root;
    SdFile file;
    char filename[30];
    unsigned long file_size;
    
       // format.  fill the arrays with ff
       for( i = 0; i < 80; ++i ) my_fat[i] = 0xff;
       for( i = 0; i < DIR_SIZE; ++i ) my_dir[i] = 0xff;
    
       // set the system area's in the fat
       for( i = 0; i < 6; ++i ) my_fat[i] = 0xfe;   // boot tracks 0,1,2
       my_fat[40] = 0xfe;  my_fat[41] = 0xfe;       // directory track 20 uses 2 clusters
    
       root.open("/M200ROOT/SCRTCH",O_RDONLY);      // open directory
       root.rewind();
       while(file.openNext(&root,O_RDONLY)){        // open each file in directory
           file.getName(filename,29);
           file_size = file.fileSize();
    
           // add this file to the fake directory and fake FAT
    
           Serial.print(filename);  Serial.write(' '); Serial.println(file_size);
           file.close();
       }
       root.close();
      
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •