Initial commit. First Iteration of Flatten.

This commit is contained in:
Eero Holmala 2023-10-23 19:11:03 +03:00
commit 838d0cdd5b
3 changed files with 83 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/build
/.vscode
/.vs

23
CMakeLists.txt Normal file
View File

@ -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)

57
main.cpp Normal file
View File

@ -0,0 +1,57 @@
#include <iostream>
#include <fstream>
#include <filesystem>
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;
}