AnsweredAssumed Answered

f_open directory name from variable

Question asked by Lori B. on Sep 18, 2014
Latest reply on Sep 18, 2014 by Montassar BEN ROMDHANE

I'm using a STM32F4  microcontroller witch FatFS library and I'm trying to write a file on an USB OTG drive. I'm using the f_open function and it works fine like that

if(f_open(&fileW, "0:\\Folder\\INFO.TXT",FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)
 { ...writing the file...

What I want now is to write the file in a folder which name is in a variable.
This is what my code looks like now:

int len = strlen(FolderName)+strlen("0:\\\\INFO.TXT")+1;
char PathString[len];
snprintf(PathString,len,"0:\\%s\\INFO.TXT", FolderName);
TCHAR str[len], *t = str;
char *s = PathString;

       *t++ = (TCHAR)*s++;
*t = 0;

if(f_open(&fileW, str, FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)
   {   ..writing..

..but it's not working. If I remove the "\\" from the path name, I can create a file named  FolderNameINFO.txt in the main root, so the  conversion TCHAR and the f_open function seem to work. But when I add the "\\" to create a folder path, I'm not able to go into the if condition.

What am I doing wrong? Thank you!