Index: code/branches/console/src/core/ArgumentCompletionFunctions.cc
===================================================================
--- code/branches/console/src/core/ArgumentCompletionFunctions.cc	(revision 1441)
+++ code/branches/console/src/core/ArgumentCompletionFunctions.cc	(revision 1442)
@@ -30,5 +30,5 @@
 #include <map>
 
-#include <dirent.h>
+#include "boost/filesystem.hpp"
 
 #include "ArgumentCompletionFunctions.h"
@@ -39,5 +39,4 @@
 #include "util/Convert.h"
 #include "util/String.h"
-#include "util/SubString.h"
 
 namespace orxonox
@@ -55,41 +54,35 @@
             ArgumentCompletionList filelist;
 
-            SubString tokens(fragment, "/", "", false, '\0', false, '\0', false, '\0', '\0', false, '\0');
+            try
+            {
+                boost::filesystem::path input(fragment);
+                boost::filesystem::path startdirectory(input.branch_path());
 
-            std::string startdirectory = ".";
-            if (fragment.size() > 0 && fragment[fragment.size() - 1] == '/' && tokens.size() > 0)
-                startdirectory = tokens.subSet(0, tokens.size()).join("/");
-            else if (tokens.size() > 1)
-                startdirectory = tokens.subSet(0, tokens.size() - 1).join("/");
+                if (!boost::filesystem::exists(startdirectory))
+                {
+                    startdirectory = ".";
+                }
+#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
+                else
+                {
+                    std::string dir = startdirectory.string();
+                    if (dir.size() > 0 && dir[dir.size() - 1] == ':')
+                        startdirectory = dir + "/";
+                }
+#endif
 
-            struct stat fileInfo;
-            struct dirent *currentFile;
-            DIR *handler = 0;
+                boost::filesystem::directory_iterator file(startdirectory);
+                boost::filesystem::directory_iterator end;
 
-            handler = opendir(startdirectory.c_str());
-            if (handler)
-            {
-                while ((currentFile = readdir(handler)) != 0)
+                while (file != end)
                 {
-                    if (strcmp(currentFile->d_name, ".") && strcmp(currentFile->d_name, ".."))
-                    {
-                        std::string path = startdirectory + "/" + currentFile->d_name;
-                        if (stat(path.c_str(), &fileInfo) == -1)
-                        {
-                            closedir(handler);
-                            break;
-                        }
-
-                        if (S_ISREG(fileInfo.st_mode)) // normal file
-                            filelist.push_back(ArgumentCompletionListElement(path, getLowercase(path), currentFile->d_name));
-                        else if (S_ISDIR(fileInfo.st_mode)) // directory
-                            dirlist.push_back(ArgumentCompletionListElement(path + "/", getLowercase(path) + "/", std::string(currentFile->d_name) + "/"));
-                        else // special file
-                            filelist.push_back(ArgumentCompletionListElement(path, getLowercase(path), currentFile->d_name));
-                    }
+                    if (boost::filesystem::is_directory(*file))
+                        dirlist.push_back(ArgumentCompletionListElement((*file).string() + "/", getLowercase((*file).string()) + "/", (*file).leaf() + "/"));
+                    else
+                        filelist.push_back(ArgumentCompletionListElement((*file).string(), getLowercase((*file).string()), (*file).leaf()));
+                    ++file;
                 }
-
-                closedir(handler);
             }
+            catch (...) {}
 
             filelist.insert(filelist.begin(), dirlist.begin(), dirlist.end());
Index: code/branches/console/src/core/CMakeLists.txt
===================================================================
--- code/branches/console/src/core/CMakeLists.txt	(revision 1441)
+++ code/branches/console/src/core/CMakeLists.txt	(revision 1442)
@@ -46,3 +46,4 @@
   ${OIS_LIBRARIES}
   ${Boost_thread_LIBRARIES}
+  ${Boost_filesystem_LIBRARIES}
 )
Index: code/branches/console/src/core/OutputBuffer.cc
===================================================================
--- code/branches/console/src/core/OutputBuffer.cc	(revision 1441)
+++ code/branches/console/src/core/OutputBuffer.cc	(revision 1442)
@@ -81,8 +81,8 @@
 
         if (eof)
-        {
             this->stream_.flush();
+
+        if (eof || fail)
             this->stream_.clear();
-        }
 
         return (!eof && !fail);
