Truncated file name problem on sd card

How do I solve the file name in the arduino and sd card module that is truncated? for example the truncated file databa~1.TXT should be database.TXT, I made a code to read all the files or some kind of file list on the sd card but the problem is that the name is truncated, is there a solution to this problem?

databa~1.TXT looks like the 8.3 version of a longer filename. How were the files created and what filenames do you see if you look at the SD card on your PC ?

database.TXT

what is the solution to this problem?

On the PC, copy database,txt to temp.txt, delete database.txt, copy temp.txt to database.txt and try reading the directory again on the Arduino

If that does not work then please post your sketch that reads the directory

yes it should work but my project this time displays all the data on the sd card to the LCD, I have created a script to read all the files on the sd card or called a file list like this: https://www.youtube.com/watch?v=r6qD2OthkN0&t=318s then is there a way to solve this 8.3?

Please post your sketch here

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

File root;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
  }

  Serial.println("Initializing SD card...");
  if (!SD.begin(10)) {
    Serial.println("Initialization failed!");
    return;
  }
  Serial.println("Initialization done.");

  root = SD.open("/"); 
  printDirectory(root, 0);
  Serial.println("Done");
  root.close(); 
}

void loop() {
}

void printDirectory(File dir, int numTabs) {
  while (true) {
    File entry = dir.openNextFile();
    if (!entry) {
      break;
    }
    if (strcmp(entry.name(), "System Volume Information") != 0) {
      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 {
        Serial.print("\t\t");
        Serial.println(entry.size(), DEC);
      }
    }
    entry.close();
  }
}
 

I modified some of the code so that the files on the system would not be read but it failed.

You should be able to use the filenaname "database.txt" even if you see "databa~1.txt" Newer operating systems keeps both names.

Use the SDfat library; it supports long filenames.

yes, but the problem is that I display it on the LCD, if someone adds a new file on the sd card, the code will still read the file name without me having to set it in the code to display a long name.

Where can I get the documentation?

This is the library, probably also available in library manager: GitHub - greiman/SdFat: Arduino FAT16/FAT32 exFAT Library

From that page:

Only use 7.3 file names. That is to say, not filename.txt rather filenam.txt

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.