C++ Library to handle BagIt structures. BagIt is a standard format to create transfer packages for digital preservation purposes. See https://en.wikipedia.org/wiki/BagIt for details http://andreas-romeyke.de
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

#include "payload.hpp"
#include <boost/filesystem.hpp>
#include <iostream>
#include <string>
#include <list>
//#include <filesystem> // c++17
//namespace fs = std::filesystem;
namespace fs = boost::filesystem;
using namespace std;
payload::payload( string basedir ) {
fs::path p{ basedir };
fs::file_status s = fs::status( p );
cout << "basedir "<< p.string() << endl;
cout << "is dir: "<< fs::is_directory( s) << endl;
cout << "exists: "<< fs::exists(s) << endl;
this->basedir = basedir;
};
void payload::scan_dir_recursively( fs::path directory, list<fs::path> &paths) {
fs::directory_iterator iter(directory), end;
for (; iter != end; ++iter) {
fs::path subdir = iter->path();
paths.push_back( subdir );
// dive deeper
payload::scan_dir_recursively( subdir, paths );
}
}
list<string> payload::get_all_relative_paths() {
list<fs::path> paths;
list<string> strpaths;
fs::path directory(this->basedir);
payload::scan_dir_recursively( directory, paths);
list<fs::path>::iterator i;
for (i=paths.begin(); i!= paths.end(); i++) {
strpaths.push_back( (*i).relative_path().string() );
}
return strpaths;
}
list<string> payload::get_all_absolute_paths() {
list<string> paths;
fs::path directory(this->basedir);
fs::directory_iterator iter(directory), end;
for (; iter != end; ++iter) {
paths.push_back( iter->path().string() );
}
return paths;
}