Add printing of usage, Add prepending a number for copied files
This commit is contained in:
parent
838d0cdd5b
commit
ba95940601
15
main.cpp
15
main.cpp
@ -1,3 +1,4 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
@ -5,7 +6,7 @@
|
||||
void
|
||||
print_usage()
|
||||
{
|
||||
|
||||
std::cout << "\tUsage:\n\t\tflatten <directory_path>\n";
|
||||
}
|
||||
|
||||
bool
|
||||
@ -17,21 +18,24 @@ CreateDumpDirectory(std::filesystem::path& path) {
|
||||
}
|
||||
|
||||
void
|
||||
RecursivelyCopyDirectoryFiles(const std::filesystem::path& cwd, const std::filesystem::path& dumpDirectory) {
|
||||
RecursivelyCopyDirectoryFiles(const std::filesystem::path& cwd, const std::filesystem::path& dumpDirectory, int& counter) {
|
||||
|
||||
for (const auto& entry : std::filesystem::directory_iterator(cwd)) {
|
||||
const auto filenameStr = entry.path().filename().string();
|
||||
|
||||
if (entry.is_directory()) {
|
||||
RecursivelyCopyDirectoryFiles(entry.path(), dumpDirectory);
|
||||
std::cout << "Entering " << cwd << "\n";
|
||||
RecursivelyCopyDirectoryFiles(entry.path(), dumpDirectory, counter);
|
||||
}
|
||||
else if (entry.is_regular_file()) {
|
||||
auto dest = dumpDirectory;
|
||||
dest /= filenameStr;
|
||||
dest /= std::to_string(counter)+"_"+filenameStr;
|
||||
if(!std::filesystem::exists(dest)){
|
||||
std::cout << "Copying from " << cwd << " to " << dest << "\n";
|
||||
if(!std::filesystem::copy_file(entry.path(), dest)){
|
||||
std::cout << "Could not copy from " << cwd << " to " << dest << "\n";
|
||||
} else {
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,7 +55,8 @@ main(int argc, char** argv){
|
||||
std::cout << "Could not create directory to flatten to!\n";
|
||||
return 1;
|
||||
}
|
||||
RecursivelyCopyDirectoryFiles(std::filesystem::path(argv[1]), dumpPath);
|
||||
int counter = 0;
|
||||
RecursivelyCopyDirectoryFiles(std::filesystem::path(argv[1]), dumpPath, counter);
|
||||
std::cout << "Done" << "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user