I am running through a directory containing multiple sub-directories. I am using recursive_directory_iterator. I have directory asr->collections->(multiple directories and couple of text files)
#include <iostream>
#include <filesystem>
#include <conio.h>
using namespace std::tr2::sys;
int main () {
std::string path_;
std::cout << " Enter the path ";
std::cin >> path_;
auto dir_path = path(path_);
for (auto it = directory_iterator(dir_path); it != directory_iterator(); ++it)
{
const auto& file = it->path();
std::cout << " path : " << file << std::endl;
if (is_directory (status(it->path())))
std::cout << " It is a directory. " << std::endl;
else
std::cout << " It is not a directory. " << std::endl;
}
_getch();
return 0;
}
I know I had posted this earlier. It was a silly mistake, I changed it. But it is still bugy. The issue I am having is the is-directory returns false for everything. Am I using it wrong. I have linked the MSDN URL below.
I installed boost and ran the code. It worked ! Boost Source
#include <iostream>
#include <boost\filesystem.hpp>
#include <conio.h>
using namespace boost::filesystem;
int main () {
std::string path_;
std::cout << " Enter the path ";
std::cin >> path_;
auto dir_path = path(path_);
for (auto it = directory_iterator(dir_path); it != directory_iterator(); ++it)
{
const auto& file = it->path();
std::cout << " path : " << file << std::endl;
if (is_directory (status(it->path())))
std::cout << " It is a directory. " << std::endl;
else
std::cout << " It is not a directory. " << std::endl;
}
_getch();
return 0;
}
http://msdn.microsoft.com/en-us/library/hh874754.aspx
Also, can I use the boost filesystem documentation be used as a tutorial for this, since there is no good documentation as to what is what and how to use it.
Ok, the issue was fixed after I updated the Visual Studio with first major update.