#include <iostream>
#include <string>
#include <boost/filesystem.hpp>
int main()
{
std::string test = "C:\\test\\test.txt";
boost::filesystem::path p(test); // avoid repeated path construction below
if (exists(p)) // does path p actually exist?
{
if (is_regular_file(p)) // is path p a regular file?
{
std::cout << p << " size is " << file_size(p) << '\n';
}
elseif (is_directory(p)) // is path p a directory?
{
std::cout << p << " is a directory\n";
}
else
{
std::cout << p << " exists, but is not a regular file or directory\n";
}
}
else
{
std::cout << p << " does not exist\n";
}
}
"C:\test\test.txt" size is 788
Your path string could also be: std::string path = "C:/test/test.txt";