赞
踩
有的时候需要比较两个目录中有什么不同的文件,可以使用如下方法:
- #include <iostream>
- #include <filesystem>
- #include <set>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <algorithm>
- using namespace std::filesystem;
- using namespace std;
-
- void getEachFile(const string& rootFolder, const string& folder, set<string>& fileSet)
- {
- directory_iterator iterDir(folder);
- for (auto &it: iterDir)
- {
- if(it.is_regular_file())
- {
- string&& filePath = it.path().string().substr(rootFolder.length() + 1);
- fileSet.emplace(filePath);
- }
- else if(it.is_directory())
- {
- getEachFile(rootFolder, it.path().string(), fileSet);
- }
- }
- }
-
-
- template<class T>
- set<T> getDiff(set<T>& ori1, set<T>& ori2)
- {
- set<T> result;
- set_difference(ori1.begin(), ori1.end(), ori2.begin(), ori2.end(), inserter(result, result.begin()));
- return result;
- }
-
- int main()
- {

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。