From ba95940601b19622ddbfd460f40040eccf8a457b Mon Sep 17 00:00:00 2001 From: Eero Holmala Date: Mon, 6 Nov 2023 10:38:20 +0200 Subject: [PATCH] Add printing of usage, Add prepending a number for copied files --- main.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index bdb6e53..001e643 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -5,7 +6,7 @@ void print_usage() { - + std::cout << "\tUsage:\n\t\tflatten \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; }