max size of filename to save on sd card

Saskia
Posts: 40
Joined: Mon Jun 26, 2017 11:45 am

max size of filename to save on sd card

Postby Saskia » Sat Aug 05, 2017 7:53 pm

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);


User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: max size of filename to save on sd card

Postby loboris » Sat Aug 05, 2017 8:36 pm

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)

User avatar
martinayotte
Posts: 141
Joined: Fri Nov 13, 2015 4:27 pm

Re: max size of filename to save on sd card

Postby martinayotte » Sun Aug 06, 2017 3:35 pm

printf("/sdcard/file.txt", buf);
That line of code doesn't make sense ...

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: max size of filename to save on sd card

Postby ESP_igrr » Sun Aug 06, 2017 4:09 pm

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);

jubueche
Posts: 32
Joined: Sat Jan 19, 2019 4:03 pm

Re: max size of filename to save on sd card

Postby jubueche » Fri Feb 08, 2019 2:15 pm

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!

mitchk
Posts: 16
Joined: Fri Apr 28, 2017 8:31 pm

Re: max size of filename to save on sd card

Postby mitchk » Thu Feb 28, 2019 9:59 pm

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.

Who is online

Users browsing this forum: No registered users and 71 guests