I'm using Boost but I cannot find complete (or good) documentation about the filesystem library in the installation directory nor the web. The "-ls" example I found has been quite a helper but it's not enough.
Thanks in advance :)
Here is an example:
#include <iostream>
#include <boost/filesystem.hpp>
#include <string>
using namespace std;
int main() {
string filename = "hello.txt";
string extension = boost::filesystem::extension(filename);
cout << "filename extension: " << extension << endl;
return 0;
}
The output is ".txt"
Reminder: Compile with '-lboost_system -lboost_filesystem'
How about:
http://www.boost.org/doc/libs/1_39_0/libs/filesystem/doc/index.htm
The functions for figuring out the file type (directory, normal file etc.) is found on this subpage: http://www.boost.org/doc/libs/1_39_0/libs/filesystem/doc/reference.html#file_status
If you are looking for the file extension check out: template <class Path> typename Path::string_type extension(const Path &p);
on the page:
http://www.boost.org/doc/libs/1_39_0/libs/filesystem/doc/reference.html#Convenience-functions
Here is an example of how you can fetch extension from files :
std::vector<boost::filesystem::path> GetAllFileExtensions()
{
std::vector<boost::filesystem::path> fileExtensions;
boost::filesystem::directory_iterator b(boost::filesystem::current_path()), e;
for (auto i=b; i!=e; ++i)
{
boost::filesystem::path fe = i->path().extension();
std::cout << fe.string() << std::endl;
fileExtensions.push_back(fe);
}
return fileExtensions;
}
std::vector<boost::filesystem::path> fileExtensions = GetAllFileExtensions();
This example just takes all files and strips extension from them and shows on standard output, you could modify function GetAllFileExtensions to only look at one file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With