Well, I spent a few hours fighting this function...
All I want to do is read the directory from an SD card and display a list of files with their sizes and time and date information.
I am using the opendir() function and then readdir("/sd") which gives, each time it is called, only a pointer to the current filename (or directoryname when present) and no attributes.
In FatDirHandle.cpp I see that the fileinfo is read in but only used to get access to the long filename. How do I get access to the other fileinfo from my program?
For testing I added a printf in FatDirHandle to show the available fileinfo:
struct dirent *FATDirHandle::readdir() {
FILINFO finfo;
#if _USE_LFN
finfo.lfname = cur_entry.d_name;
finfo.lfsize = sizeof(cur_entry.d_name);
#endif // _USE_LFN
FRESULT res = f_readdir(&dir, &finfo);
printf("File %s filesize: %d attribute %02x\n\r",finfo.fname,finfo.fsize,finfo.fattrib);
#if _USE_LFN
if (res != 0 || finfo.fname[0]==0) {
return NULL;
} else {
if (cur_entry.d_name[0]==0) {
// No long filename so use short filename.
memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
}
return &cur_entry;
}
#else
if (res != 0 || finfo.fname[0]==0) {
return NULL;
} else {
memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
return &cur_entry;
}
#endif /* _USE_LFN */
}
Well, I spent a few hours fighting this function... All I want to do is read the directory from an SD card and display a list of files with their sizes and time and date information.
I am using the opendir() function and then readdir("/sd") which gives, each time it is called, only a pointer to the current filename (or directoryname when present) and no attributes.
In FatDirHandle.cpp I see that the fileinfo is read in but only used to get access to the long filename. How do I get access to the other fileinfo from my program?
For testing I added a printf in FatDirHandle to show the available fileinfo: