Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ESPFlash: Truncate a filename in excess of 32 characters so it can be used with SPIFFS.
/*
Truncate a filename in excess of 32 characters so it can be
used with SPIFFS.
*/
/* Filenames are automatically truncated if in excess of 32 characters */
/* The file extension is preserved */
ESPFlash<float> floatExample("/thisFilenameIsLargerThan32Characters.txt");
/* The above code replaces the following SPIFFS implementation */
const char* filename = "/thisFilenameIsLargerThan32Characters.txt";
char filenameBuffer[32];
if(strlen(fileName) < 32)
{
strcpy(filenameBuffer, fileName);
}
else
{
strncpy(this->fileName, fileName, 27);
char* pch = strrchr(fileName, '.');
strcpy(filenameBuffer+27, pch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment