Trying to build a program that scans a directory and generates MD5 hash for each file. Using boost and crypto++ in C++14
Struggling to get my head around the path vectors and passing the individual items to the crypto++ FileSource function.
See examples below with a fixed path. If anyone could let me know how to convert the directory elements to a type that is accepted by the FileSource function in the for loop that would be great.
if (exists(p)) {
if (is_regular_file(p)) {
cout << "Please enter base path of directory only." << endl;
}
else if (is_directory(p)){
cout << "Scanning " << p << endl;
typedef vector<path> vec;
vec v;
copy(directory_iterator(p), directory_iterator(), back_inserter(v));
sort(v.begin(), v.end());
for (vec::const_iterator it (v.begin()); it != v.end(); ++it)
{
string result;
Weak::MD5 hash;
FileSource("/home/howard/Documents/projects/copy_project/MultiCopy/main.cpp", true, new HashFilter(hash, new HexEncoder(new StringSink(result), false)));
cout << " " << *it << " : " << result << endl;
}
This works as expected, prints out the following:
Scanning "/home/howard/Documents/projects/copy_project/"
"/home/howard/Documents/projects/copy_project/MultiCopy" : e4e336e768990b515a573dc5f60e5b8b
"/home/howard/Documents/projects/copy_project/cryptopp_example" : e4e336e768990b515a573dc5f60e5b8b
"/home/howard/Documents/projects/copy_project/md5_example" : e4e336e768990b515a573dc5f60e5b8b
"/home/howard/Documents/projects/copy_project/md5_from_file" : e4e336e768990b515a573dc5f60e5b8b
"/home/howard/Documents/projects/copy_project/scan_dir" : e4e336e768990b515a573dc5f60e5b8b
Tried below, but this does not work.
FileSource(*it, true, new HashFilter(hash, new HexEncoder(new StringSink(result), false)));