Reading folder from SD Card runs fine the first call, second time it fails. Why?
hello,
i trying access content in folders on sd card.
assuming have structure on sd-card:
set1\ <dir> 04.06.13 12:50:20 9 ---- q:\ 2013-06-04 12-50-18
rbowhlf4.bmp 62.454 30.05.13 02:16:30 -a-- q:\ 2013-06-04 15-31-41
rbowhlf9.bmp 62.456 03.06.13 21:28:40 -a-- q:\ 2013-06-04 15-31-38
in folder "set1\" there bmp-files.
now when first time read in content of root folder, runs fine. both 2 files , directory read internal array.
then read content of "set1" once. after try read root again, files in root detected, folder "set1" seems invisible. have idea why might be?
i trying access content in folders on sd card.
assuming have structure on sd-card:
set1\ <dir> 04.06.13 12:50:20 9 ---- q:\ 2013-06-04 12-50-18
rbowhlf4.bmp 62.454 30.05.13 02:16:30 -a-- q:\ 2013-06-04 15-31-41
rbowhlf9.bmp 62.456 03.06.13 21:28:40 -a-- q:\ 2013-06-04 15-31-38
in folder "set1\" there bmp-files.
now when first time read in content of root folder, runs fine. both 2 files , directory read internal array.
then read content of "set1" once. after try read root again, files in root detected, folder "set1" seems invisible. have idea why might be?
code: [select]
void getfilenamesfromsd(string* strdir, bool iroot)
{
lcd.clear();
lcd.print("scanning files ");
file dirroot;
char temp[14];
strdir->tochararray(temp,14);
dirroot = sd.open(temp);
m_numberoffiles = 0;
m_fileindex = 0;
int filecount = 0;
string currentfilename = "";
int strlength = 0;
if(iroot == false) // add fake parent directory list when not in root
{
m_sdfiles[filecount] = sdfile("..",type_directory);
filecount++;
}
while(1)
{
file entry = dirroot.opennextfile();
if (! entry) {
// no more files
m_numberoffiles = filecount;
entry.close();
dirroot.rewinddirectory();
break;
}
else
{
currentfilename = entry.name();
if (entry.isdirectory())
{
currentfilename.touppercase();
m_sdfiles[filecount] = sdfile(currentfilename,type_directory);
filecount++;
//getnextfilename(root);
}
else {
currentfilename.tolowercase();
if (currentfilename.endswith(".bmp")) { //find files our extension only
// strlength = currentfilename.length();
// currentfilename = currentfilename.substring(0, (currentfilename.length() - 4));
lcd.setcursor(0, 1);
lcd.print(currentfilename);
// m_filenames[filecount] = currentfilename;
m_sdfiles[filecount] = sdfile(currentfilename,type_bitmap);
filecount++;
}
}
}
entry.close();
}
dirroot.close();
}
Arduino Forum > Using Arduino > Storage > Reading folder from SD Card runs fine the first call, second time it fails. Why?
arduino
Comments
Post a Comment