Can't list files after writting on a file

I want to list the files of my SD card many times, but after I open a file and write on it I can't list the files again. I think that the program wants to list from the position of my last file and that's why I dont see anything. Any suggestions?

#include <SPI.h>
#include <SD.h>
File root;
void setup()
  // Open serial communications and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
  Serial.println("initialization done.");

void loop()

  root ="/");
  printDirectory(root, 0);

  File dataFile ="012011.TXT", FILE_WRITE);
  delay (5000);
  // nothing happens after setup finishes.

void printDirectory(File dir, int numTabs) {
   while(true) {
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
     for (uint8_t i=0; i<numTabs; i++) {
     if (entry.isDirectory()) {
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.println(entry.size(), DEC);

Same thing happened to me. Its a "bug" if you do a; after the root open then it will work. I was "removing" files, removed the last file and could not list again. Removed a file in the middle and the next file was first in the list when i called list directory. Must be that the code does not reset a pointer to the directory block when an open to "root" is called.