#include <fstream>
#include <iostream>
#include <sys/types.h>
#include <dirent.h>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/iostreams/filtering_stream.hpp>
using namespace std;
using namespace boost::iostreams;
void decompress (string source, string filename)
{
ifstream file(source.c_str(), ios_base::in | ios_base::binary);
ofstream out(filename.c_str(), ios_base::out | ios_base::binary);
filtering_streambuf<input> in;
in.push(zlib_decompressor());
in.push(file);
boost::iostreams::copy(in, out);
}
int main ()
{
string source;
string filename;
char result;
DIR* dir = opendir("/home/pablo/testee");
struct dirent* ent = 0;
while (dir && (ent = readdir(dir))) {
filename = ent->d_name;
string new_filename = filename;
result = new_filename.find_last_of('.');
if (std::string::npos != result)
{
new_filename.erase(result);
}
filename.append(".txt");
decompress(ent->d_name, filename);
}
closedir(dir);
return 0;
}
|