I can not find the cause of this error, the line I think the error occurs on is:
for (boost::filesystem::recursive_directory_iterator iterator(directory); iterator != end_iterator; ++iterator)
Nothing past this point will run, I get this error:
Exception thrown at 0x75ACDAE8 in Game.exe: Microsoft C++ exception: boost::filesystem::filesystem_error at memory location 0x008FF8E0.
Unhandled exception at 0x75ACDAE8 in Game.exe: Microsoft C++ exception: boost::filesystem::filesystem_error at memory location 0x008FF8E0.
I would post more relevant code, but I am totally lost with this error.
It told you that you didn't catch the exception. Catch it, and print its what(), it will tell you what the problem was. The most common problem is that directory doesn't exist:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <boost/filesystem.hpp>
#include <iostream>
namespace fs = boost::filesystem;
int main() try
{
fs::path directory = "C:This\\Doesn't\\Exist";
for(fs::path p : fs::recursive_directory_iterator(directory)) // C++11 version of yours
{
std::cout << p << '\n';
}
} catch(const fs::filesystem_error& e) {
std::cout << e.what() << '\n';
}
#include "Filesystem.h"
#include <vector>
#include <string>
#include <boost/filesystem.hpp>
#include <algorithm>
#include <iostream>
std::vector<std::string> Filesystem::scan(std::string directory, std::vector<std::string> filters)
{
//Stores index of directory
std::vector<std::string> index;
//This is the end iterator
boost::filesystem::recursive_directory_iterator end_iterator;
//Cycle through the directory(and subdirectories)
try
{
for (boost::filesystem::recursive_directory_iterator iterator(directory); iterator != end_iterator; ++iterator)
{
//push back name of current file to vector
std::string current_directory = iterator->path().string();
std::cout << current_directory << std::endl;
//add it to the index(but not if filtered out)
for (constauto& filter : filters)
{
//If there is no filter
if (filter == "*")
{
//Add to index
index.push_back(current_directory);
break;
}
//if this file has an acceptible extension(filtered)
elseif (iterator->path().extension() == filter)
{
std::cout << current_directory << std::endl;
index.push_back(current_directory);
}
}
}
}
catch (const boost::filesystem::filesystem_error& e)
{
std::cout << e.what() << '\n';
}
return index;
}