Index: trunk/src/lib/util/directory.cc
===================================================================
--- trunk/src/lib/util/directory.cc	(revision 7661)
+++ trunk/src/lib/util/directory.cc	(revision 8276)
@@ -38,110 +38,114 @@
 
 #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>
+
+/**
+ * @brief Constructs a Directory handler.
+ * @param directoryName the name of the Directory to access.
+ */
 Directory::Directory(const std::string& directoryName)
-  : File(directoryName), willfail(false)
+    : File(directoryName)
 {
-  this->handle = 0;
-  this->willfail = true;
+  this->_opened = false;
 }
 
+/**
+ * @brief destructs the Directory.
+ */
 Directory::~Directory()
 {
+  this->close();
 }
 
+
+/**
+ * @brief openes the Directory
+ * @returns true on success, false on error. (does not exist, no rights -> test with functions of File)
+ *
+ * Fills the List of Files, and sets the Directory to open state
+ */
 bool Directory::open()
 {
+  if (this->_opened)
+    this->close();
+
+  // Openes the Directory for reading:
 #if not defined(__WIN32__)
-  if (this->handle != NULL)
-    this->close();
-  this->handle = opendir(this->name().c_str());
+  DIR* handle;
+  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;
+
+  // 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__)
+  dirent* entry;
+  while ((entry = readdir(handle)) != NULL)
+    this->_fileNames.push_back(entry->d_name);
+  closedir(handle);
+#else
+  WIN32_FIND_DATA entry;
+  while ((int ok = FindNextFile(handle, &entry)) != 0)
+    this->_fileNames.push_back(entry.cFileName);
+  FindClose(handle);
+#endif
+  this->_opened = true;
+  return true;
 }
 
+/**
+ * @brief closes the directory
+ * @returns true.
+ *
+ * Clears the List of Files in the Directory.
+ */
 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
-}
-
-
+/**
+ * @brief creates the directory
+ * @returns true on success, false on error
+ */
 bool Directory::create()
 {
