2013-10-21 07:37 AM
Hi everyone,
I have a doubt and i hope someone can help me.I'm writting my SD card files with .001, .002, .003, etc extension. I need to know which is the biggest extension of my files. I'm using Fat32. Is there any function that return wich is the biggest extension of my files?Thanks in advance!Miquel2013-10-21 07:56 AM
No, you'll need to enumerate through the files yourself. Suggest looking at f_opendir() and f_readdir()
2013-10-24 02:38 AM
Hi Clive,
Thanks for responding. I will enumerate it myself, but I want to know which is the biggest extension to continue writing the next. For example, I have created three files: .001, .002 and .003 extension. When I execute my program, I need to check which is the biggest extension (.003) to start writing in the next (.004). I have an array char nomarxiu [12] = ''P9V26N09.001'';and I want to check if last three positions (extension) in my SD card exist or not, to call later the functionrc = f_open(&Fil2, nomarxiu, FA_WRITE | FA_CREATE_ALWAYS);with the correct values in the extension.Thanks,Miquel2013-10-24 10:08 AM
Yes, you'll need to use f_readdir() and identify the highest index currently used. To do this you'll need to parse the filename/extension returned and extract the data that is pertinent to your requirement.
I understood the requirement as first expressed, I'm just not looking to own this coding task.2013-10-25 02:33 AM
Ok, I'll try using f_raddir() right now! With a single call to the function I will receive all the files? Should I make a for loop to get all the files? And if my files are in the root, which parameters should I put in the function?
FRESULT f_readdir ( DIR*
dp
,/* [IN] Directory object */
FILINFO*fno
/* [OUT] File information structure */
);Thanks!Miquel2013-10-25 03:03 AM
It allows you to enumerate through the directory content one file at a time. They will appear in the order they are in the directory, which may not be linear/sorted, so make no assumptions there.
Please refer to the documentation if the function usage is not familiar to you, as it also provides a worked example.http://elm-chan.org/fsw/ff/en/readdir.html
2013-10-28 03:29 AM
I'm trying to use f_readdir(), but I need to have to dp parameter (directory object). I want to search in the root, and I think i have to use f_opendir() to give it in the path parameter. I read
and it seems that I have to write something like this: rc = f_opendir(&dir, '' ''); but I have a question.The f_closedir() doesn't exist in my keil libraries. Can I do it without opendir(), only with f_readdir()?Thanks!Miquel2013-10-28 05:29 AM
I'm not sure how Keil plays into this the, some versions may not have/need f_closedir
res = f_opendir(&dir, ''''); // Root directory, empty string (no space) Try to use the library as intended, don't try to invent new methods. If the f_opendir is not working, examine the result code.FRESULT res;
FILINFO fno;
FIL fil;
DIR dir;
char* path;
char *fn; /* This function is assuming non-Unicode cfg. */
#if _USE_LFN
static char lfn[_MAX_LFN + 1];
fno.lfname = lfn;
fno.lfsize = sizeof lfn;
#endif
path = '''';
res = f_opendir(&dir, path);
if (res != FR_OK)
printf(''res = %d f_opendir
'', res);
if (res == FR_OK)
{
while(1)
{
char *fn;
res = f_readdir(&dir, &fno);
if (res != FR_OK)
printf(''res = %d f_readdir
'', res);
if ((res != FR_OK) || (fno.fname[0] == 0))
break;
#if _USE_LFN
fn = *fno.lfname ? fno.lfname : fno.fname;
#else
fn = fno.fname;
#endif
printf(''%c%c%c%c '',
((fno.fattrib & AM_DIR) ? 'D' : '-'),
((fno.fattrib & AM_RDO) ? 'R' : '-'),
((fno.fattrib & AM_SYS) ? 'S' : '-'),
((fno.fattrib & AM_HID) ? 'H' : '-') );
printf(''%10d '', fno.fsize);
printf(''%s/%s
'', path, fn);
}
}
2013-10-29 05:42 AM
Hi Clive,
I've changed what you say and now it works perfectly, but when I want to write for example 1000kb, the program only writes 389kb, is like there was a maximum allowable value.Is this true? And if so, how can I change it?Thanks,Miquel2013-10-29 08:39 AM
I'm writing multiple megabytes, no magic required.
Make sure you are closing the files. Make sure the WRITE of the SD Card is occurring, and correct. Add a verify phase if that helps debug the issue.