Go Down

Topic: Detecting a blank filename (Read 194 times) previous topic - next topic


Nov 18, 2020, 11:45 pm Last Edit: Nov 18, 2020, 11:46 pm by phoneystark2020

When I search my SD card so set a certain file as a 'boot' file, I need to eliminate files that are not compatible.

I have been using:

Code: [Select]

    if (strncmp(SDname, "SYSTEM", 6) == 0) {                                                                         // Skip system file
      Serial.println("Skipping system file");
      printDirectory(root, 0);

and this works perfectly to skip the SYSTEM file on the SD card
The printDirectory routine simply retrieves the next SD file name as SDname by the way.

But, I cannot seem to get the same routine to detect an empty file name

Code: [Select]

    if (strncmp(SDname, "        ", 8) == 0) {                                                                         // Skip system file
      Serial.println("Skipping blank file");
      printDirectory(root, 0);

This doesn't work (or any combination of blank test lengths.  The filename can only be up to 8 characters.

Any ideas?


I cannot seem to get the same routine to detect an empty file name
How was the file with the blank name created ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.


But file name can be less than 8.3, can't they?



Nov 20, 2020, 11:44 pm Last Edit: Nov 20, 2020, 11:45 pm by phoneystark2020
Hello chaps.

OK, got over the issue by ensuring a blank file can never be formed in the first place.
To be honest, I have no idea how the blank name issue came about.  I don't think it's possible.

I have to say, this damn SD card has caused me nothing but issues.

My project allocates a file number to the stored data.  E.G. 12-Blue.txt  or  1-Red.txt.
The files are basically manipulated by the first 2 digits.  I can have up to 99 files on my SD card.

When I create a new data file, it searches the SD card before creating that file for any instance of a matching number. 
If there is a matching number, it advances one and checks again.

I do this with a madly complicated loop routine that takes ages  (if there are 90+ files on the SD card, then you can be waiting 90 seconds).

Can you use the: if (SD.exists(SDname)){} function to search for a match of only the first two characters?
Possibly would speed things up greatly.

My main issue is it reads the files off the SD card in the order they were written, not in alphabetically or numerical order.
You could sort the SD card outside the project, but I wanted a read systems that avoided that requirement.

My only other 'quicker' method might be to retrieve all the SD card filenames once into memory, and then search through them.  That should be quicker.

The more I type this out.... the more I realise it's a stupid way to store/sort data


Just as an update.... abandoned.

My original idea was the project could only load files that started with a file number.  But that leads to more issues than it's worth.


You could have another file which contains the filename of the highest value existing regular file.  But you would have to update that file each time you create a new regular file.

But at some level, dealing with 99 files is just going to be slow unless you are able to read in the entire contents of the directory using some low-level sector-read commands.  I don't think there's any way the FAT file system can find a file in the directory other than to start looking from the beginning, reading in 32 bytes at a time.  And it has to go through all the short filenames, the long filenames, the deleted filenames, the subdirectory entries, etc. until it either finds the name it's looking for, or comes to the end of the entries.  And it has to go through the same process to create a directory entry for a new file.

Go Up