commit 838d0cdd5ba5f3ef8f72b34a370a083e9c9fb7c8 Author: Eero Holmala Date: Mon Oct 23 19:11:03 2023 +0300 Initial commit. First Iteration of Flatten. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e6ad3a8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/build +/.vscode +/.vs \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e88c463 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.0.0) +project(flatten VERSION 0.1.0 LANGUAGES C CXX) + + + +if (MSVC_VERSION GREATER_EQUAL "1900") + include(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG("/std:c++17" _cpp_latest_flag_supported) + if (_cpp_latest_flag_supported) + add_compile_options("/std:c++17") + endif() +endif() + +include(CTest) +enable_testing() + +add_executable(flatten main.cpp) + +set_property(TARGET flatten PROPERTY CXX_STANDARD 17) + +set(CPACK_PROJECT_NAME ${PROJECT_NAME}) +set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) +include(CPack) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..bdb6e53 --- /dev/null +++ b/main.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +void +print_usage() +{ + +} + +bool +CreateDumpDirectory(std::filesystem::path& path) { + if(!std::filesystem::exists(path)) + return std::filesystem::create_directory(path); + else + return true; +} + +void +RecursivelyCopyDirectoryFiles(const std::filesystem::path& cwd, const std::filesystem::path& dumpDirectory) { + + for (const auto& entry : std::filesystem::directory_iterator(cwd)) { + const auto filenameStr = entry.path().filename().string(); + + if (entry.is_directory()) { + RecursivelyCopyDirectoryFiles(entry.path(), dumpDirectory); + } + else if (entry.is_regular_file()) { + auto dest = dumpDirectory; + dest /= 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"; + } + } + } + + } +} + + +int +main(int argc, char** argv){ + std::filesystem::path dumpPath{"dump_directory"}; + if(argc == 1){ + print_usage(); + return 0; + } + if(!CreateDumpDirectory(dumpPath)){ + std::cout << "Could not create directory to flatten to!\n"; + return 1; + } + RecursivelyCopyDirectoryFiles(std::filesystem::path(argv[1]), dumpPath); + std::cout << "Done" << "\n"; + return 0; +}