0

Right now I have the following code for the Arduino SD Library

#include <SPI.h>
#include <SD.h>

void printDirectory(File dir, int numTabs) 
{
  while (true) 
  {
    File entry =  dir.openNextFile();
    if (! entry) 
    {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) 
    {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) 
    {
      Serial.println(':');
      printDirectory(entry, numTabs + 1);
    }
    else 
    {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.print(entry.size(), DEC);
      Serial.println(":");
    }
    entry.close();
  }
}

My hangup is that for file or folder names of 9 or more characters I get back char56~1.TXT How can I get the full name of the files and folders?

Also, What is the best way to, instead of printing to the serial port, only print trees that have a .TXT (or .CSV ) extension?

  • 8.3 filenames and the FAT file system are the only type of filenames supported by the SD library. en.wikipedia.org/wiki/8.3_filename You can use the SdFat library. It supports long filenames. – KC Tucker Jun 5 '17 at 18:19
  • Ok! I'll use it. Are there any examples of how to do a recursive file/folder list with the SdFat library? Or would this code still work? – ATE-ENGE Jun 5 '17 at 18:40
  • Just see the github page... – KC Tucker Jun 5 '17 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.