summaryrefslogtreecommitdiff
path: root/mxclean/clean_files.cpp
blob: 8c3b0ad0c01c2c6bef4e306f700430ea985593db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <set>
#include <string>
#include <fstream>
#include <iostream>

using namespace std;

string path_to_id(string &s)
{
	string t = "";
	for (auto c: s) {
		if (isalpha(c))
			t = t + c;
	}
	return t;
}

int main()
{
	ifstream flist("/tmp/mxclean/filelist");
	ifstream keeplist("/tmp/mxclean/files_to_keep");
	ofstream rm("/tmp/mxclean/remove.sh");

	set<string> keep_set;
	string s;
	int keep = 0, remove = 0;

	while (keeplist >> s) {
		keep_set.insert(s);
	}

	while (flist >> s) {
		if (keep_set.find(path_to_id(s)) != keep_set.end()) {
			keep++;
		} else {
			remove++;
			rm << "rm " << s << endl;
		}
	}

	cout << "keep " << keep << " files, remove " << remove << " files." << endl;
	return 0;
}