Page 1 of 1

max size of filename to save on sd card

Posted: Sat Aug 05, 2017 7:53 pm
by Saskia
Does sdmmc has a max. size of chars for the filename to save on a sd card?
example

Code: Select all

#define random_string "foo"
char buf[100];
snprintf(buf, sizeof(buf), "/sdcard/%s.txt", random_string);
FILE *f = fopen(buf, "w");
is there a limit? or can the filename as long as i want

Also i can only save .txt file, no other file extensions.

also have problem, that sometimes this is working, sometimes not. example

Code: Select all

#define random_string "foo"
char buf[100];
printfs("printf statement should come soon..."); //but it won't - only this message appears, thats it, nothing else
snprintf(buf, sizeof(buf), "/sdcard/%s.txt", random_string);
printf("%s", buf);
FILE *f = fopen(buf, "w");
same problem here. no line will be printed

Code: Select all

printf("/sdcard/file.txt", buf);
FILE *f = fopen("/sdcard/file.txt", "w");
if (f == NULL) {
        ESP_LOGE(TAG, "Failed to open file for writing");
        return;
    }
    ESP_LOGI(TAG, "opening success");
    fclose(f);

Re: max size of filename to save on sd card

Posted: Sat Aug 05, 2017 8:34 pm
by WiFive

Re: max size of filename to save on sd card

Posted: Sat Aug 05, 2017 8:36 pm
by loboris
Run

Code: Select all

make menuconfig
and select (enable) long filename support:
→ Component config → FAT Filesystem support → Long filename support
Then you can select Max long filename length (default is 255)

Re: max size of filename to save on sd card

Posted: Sun Aug 06, 2017 3:35 pm
by martinayotte
printf("/sdcard/file.txt", buf);
That line of code doesn't make sense ...

Re: max size of filename to save on sd card

Posted: Sun Aug 06, 2017 4:09 pm
by ESP_igrr
Saskia wrote:also have problem, that sometimes this is working, sometimes not. example

Code: Select all

#define random_string "foo"
char buf[100];
printfs("printf statement should come soon..."); //but it won't - only this message appears, thats it, nothing else
snprintf(buf, sizeof(buf), "/sdcard/%s.txt", random_string);
printf("%s", buf);
Lines printed via printf/fprintf are flushed to the output stream either if the stream buffer overflows, or if newline is detected in the stream.
So if you want to see the result of second printf immediately, make sure you add a newline character:

printf("%s\n", buf);

Re: max size of filename to save on sd card

Posted: Fri Feb 08, 2019 2:15 pm
by jubueche
Can you put a note in https://docs.espressif.com/projects/esp ... kio_impl_t ? I got hung up on this and the solution is so simple!
You find it if you search for it, but I feel like this should be mentioned.
Also maybe mention that the size in the partition should be >= 1MB (if this is not already the case).

Thanks guys!

Re: max size of filename to save on sd card

Posted: Thu Feb 28, 2019 9:59 pm
by mitchk
Hi I am running into the issue of file names over 8 characters not working. I am modifying the sd_card example from the IDF and I am using version v3.3-beta1-328-gabea9e4c0 of the IDF. In the menuconfig I changed the option within FAT Filesystem Support to enable long filenames (I tried both heap and stack) but still anytime I use fopen with a filename over 8 characters (or within a directory that has a name over 8 characters) it returns NULL. I am using the default Single App No OTA partition.