Reading folder from SD Card runs fine the first call, second time it fails. Why?

Hello,

I am trying to get access to the content in folders on an SD card.

Assuming a have this structure on the SD-Card:

SET1\ 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 the folder “SET1” there are only some BMP-files.

Now when I first time read in the content of the root folder, it runs fine. Both the two files and the directory are read into an internal array.

Then I read the content of “SET1” once. After that I try to read the root again, but now only the files in the root detected, the folder “SET1” seems to be invisible. Does anyone have the idea why this might be?

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 a fake parent directory to the list when not in the 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 with 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();
}