Index: /branches/gui/src/lib/shell/shell_completion_plugin.cc
===================================================================
--- /branches/gui/src/lib/shell/shell_completion_plugin.cc	(revision 8223)
+++ /branches/gui/src/lib/shell/shell_completion_plugin.cc	(revision 8224)
@@ -100,7 +100,7 @@
       dir.setFileName(ResourceManager::getInstance()->getDataDir() + this->_subDir);
       dir.open();
-      while(dir)
+      for(unsigned int i = 0; i < dir.fileCount(); i++ )
       {
-        completionList.push_back(this->_subDir + "/" + dir.next());
+        completionList.push_back(this->_subDir + "/" + dir[i]);
       }
     }
@@ -118,7 +118,7 @@
       std::string fileName;
       std::string currFile;
-      while(dir)
+      for(unsigned int i = 0; i < dir.fileCount(); i++)
       {
-        currFile = dir.next();
+        currFile = dir[i];
         if (currFile[0] == '.')
          continue;
Index: /branches/gui/src/lib/util/directory.cc
===================================================================
--- /branches/gui/src/lib/util/directory.cc	(revision 8223)
+++ /branches/gui/src/lib/util/directory.cc	(revision 8224)
@@ -38,108 +38,93 @@
 
 #if not defined (__WIN32__)
- #include <sys/stat.h>
- #include <sys/types.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#else
+#include <windows.h>
+#include <winbase.h>
 #endif
+
+#include <iostream>
+
 Directory::Directory(const std::string& directoryName)
-  : File(directoryName), willfail(false)
+    : File(directoryName)
 {
-  this->handle = 0;
-  this->willfail = true;
+  this->_opened = false;
 }
 
 Directory::~Directory()
 {
+  this->close();
 }
+
 
 bool Directory::open()
 {
+  if (this->_opened)
+    this->close();
+
+  // Openes the Directory for reading:
 #if not defined(__WIN32__)
-  if (this->handle != NULL)
+  DIR* handle;
+  if (handle != NULL)
     this->close();
-  this->handle = opendir(this->name().c_str());
+  handle = opendir(this->name().c_str());
   if (!handle)
-    willfail = true;
+  {
+    std::cerr << "could not open directory " << this->name() << " for reading" << std::endl;
+    return false;
+  }
+#else
+  HANDLE handle;
+  if (handle != INVALID_HANDLE_VALUE)
+    this->close();
+
+  // First check the attributes trying to access a non-Directory with
+  // FindFirstFile takes ages
+  DWORD attrs = GetFileAttributes(this->name().c_str());
+  if ( (attrs == 0xFFFFFFFF) || ((attrs && FILE_ATTRIBUTE_DIRECTORY) == 0) )
+  {
+    return false;
+  }
+  std::string Full(this->name());
+  // Circumvent a problem in FindFirstFile with c:\\* as parameter
+  if ( (Full.length() > 0) && (Full[Full.length()-1] != '\\') )
+    Full += "\\";
+  WIN32_FIND_DATA entry;
+  handle = FindFirstFile( (Full+"*").c_str(), &entry);
+  if (handle == INVALID_HANDLE_VALUE)
+  {
+    std::cerr << "could not open directory " << this->name() << " for reading" << std::endl;
+    return false;
+  }
   else
   {
-    willfail = false;
-    dirent* entry = readdir(handle);
-    if (entry)
-      current = entry->d_name;
-    else
-      willfail = true;
+    this->_fileNames.push_back(entry.cFileName);
   }
-#else
-    if (handle != INVALID_HANDLE_VALUE)
-      this->close();
-
-    // First check the attributes trying to access a non-Directory with
-    // FindFirstFile takes ages
-    DWORD attrs = GetFileAttributes(this->name().c_str());
-    if ( (attrs == 0xFFFFFFFF) || ((attrs && FILE_ATTRIBUTE_DIRECTORY) == 0) )
-    {
-      willfail = true;
-      return false;
-    }
-    std::string Full(this->name());
-    // Circumvent a problem in FindFirstFile with c:\\* as parameter
-    if ( (Full.length() > 0) && (Full[Full.length()-1] != '\\') )
-      Full += "\\";
-    WIN32_FIND_DATA entry;
-    handle = FindFirstFile( (Full+"*").c_str(), &entry);
-    if (handle == INVALID_HANDLE_VALUE)
-    {
-      willfail = true;
-      return false;
-    }
-    else
-    {
-      willfail = false;
-      current = entry.cFileName;
-      return true;
-    }
 #endif
 
+  // BUILDING the list of contained Files. (only the names)
+#if not defined(__WIN32__)
+  while (dirent* entry = readdir(handle))
+    this->_fileNames.push_back(entry->d_name);
+  closedir(handle);
+#else
+  WIN32_FIND_DATA entry;
+  while (int ok = FindNextFile(handle, &entry))
+    this->_fileNames.push_back(entry.cFileName);
+  FindClose(handle);
+#endif
+  this->_opened = true;
+  return true;
 }
 
 bool Directory::close()
 {
-#if not defined(__WIN32__)
-  if (this->handle != NULL)
-    closedir(handle);
-  this->handle = NULL;
-#else
-  if (handle != INVALID_HANDLE_VALUE)
-    FindClose(handle);
-    handle = 0;
-#endif
-  this->willfail = true;
-  this->current = "";
+  this->_opened = false;
+  this->_fileNames.clear();
   return true;
 }
 
-
-
-std::string Directory::next()
-{
-#if not defined(__WIN32__)
-  std::string prev(current);
-  dirent* entry = readdir(handle);
-  if (entry)
-    current = entry->d_name;
-  else
-    willfail = true;
-  return prev;
-
-#else
-  std::string prev = current;
-  WIN32_FIND_DATA entry;
-  int ok = FindNextFile(handle, &entry);
-  if (!ok)
-    willfail = true;
-  else
-    current = entry.cFileName;
-  return current;
-#endif
-}
 
 
Index: /branches/gui/src/lib/util/directory.h
===================================================================
--- /branches/gui/src/lib/util/directory.h	(revision 8223)
+++ /branches/gui/src/lib/util/directory.h	(revision 8224)
@@ -27,12 +27,5 @@
 
 #include "file.h"
-
-#if not defined (__WIN32__)
- #include <sys/types.h>
- #include <dirent.h>
-#else
- #include <windows.h>
- #include <winbase.h>
-#endif
+#include <vector>
 
 class Directory : public File
@@ -44,18 +37,19 @@
   virtual bool open();
   virtual bool close();
-  operator void*() const { return willfail ? (void*)0:(void*)(-1); }
-
-  std::string next();
 
   bool create();
 
+  /** @returns the FileNames contained inside of the Directory */
+  const std::vector<std::string>& fileNames() const { return this->_fileNames; };
+  const std::string& operator[](unsigned int fileNumber) const { return this->_fileNames[fileNumber]; };
+  unsigned int fileCount() const { return _fileNames.size(); };
+
+  std::string fileNameInDir(unsigned int fileNumber) const { return this->name() + "/" + _fileNames[fileNumber]; };
+
+  File getFile(unsigned int fileNumber) const { return File(fileNameInDir(fileNumber)); };
+
 private:
-#if not defined(__WIN32__)
-  DIR* handle;
-#else
-  HANDLE    handle;
-#endif
-  bool willfail;
-  std::string current;
+  bool                        _opened;
+  std::vector<std::string>    _fileNames;
 };
 
