Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <string>
- #include <cstring>
- #include <filesystem>
- using namespace std;
- namespace fs = filesystem;
- int main() {
- // total pages
- int pages = 0;
- // current path is .
- string path = ".",
- path2, file;
- // needed for searching substrings
- size_t found, size;
- // auxiliary strings
- char f[100], metadata[1000];
- // looping through openboard documents
- for (const auto & entry : fs::directory_iterator(path)) {
- path2 = entry.path();
- // cout << path2 << '\n';
- // check if current entry is an openboard document
- found = path2.find("OpenBoard");
- // if not then go to the next item
- if (found == string::npos) continue;
- // loop through openboard document's files
- for (const auto & entry2 : fs::directory_iterator(path2)) {
- file = entry2.path();
- // search the metadata.rdf file
- found = file.find("metadata.rdf");
- if (found != string::npos) {
- // cout << " " << file << '\n';
- size = file.size();
- // if we find it, put the location of the file in an auxiliary string
- for (int i = 2; i < size; i++) {
- f[i-2] = file[i];
- }
- f[size-2] = '\0';
- // cout << " " << f << '\n';
- // open the file
- freopen(f, "r", stdin);
- bool found = false;
- // find the page-count
- while (cin.getline(metadata, 1000) && !found) {
- // cout << metadata << '\n';
- // search for page-count
- char *p = strstr(metadata, "page-count");
- // if we find it we form the number of pages
- if (p) {
- int n = 0;
- int k = p - metadata + 11;
- found = true;
- while ('0' <= metadata[k] && metadata[k] <= '9') {
- n = n * 10 + (metadata[k] - '0');
- k++;
- }
- cout << n << '\n';
- // add the pages to the total
- pages += n;
- }
- }
- // close current file
- fclose(stdin);
- }
- }
- }
- cout << pages << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment