diff --git a/mcopy.cpp b/mcopy.cpp index 807fcd4..b274ada 100644 --- a/mcopy.cpp +++ b/mcopy.cpp @@ -115,6 +115,12 @@ void getMetadataFromFile(std::string format, std::string str) { std::filesystem::path fs; std::string dir = (fs = filename).remove_filename(); + + if (dir.empty()) { + std::cerr << "mcopy: Failed to create directory '" << dir << "'\n"; + return; + } + std::filesystem::create_directories(dir); if (!std::filesystem::copy_file(str, filename)) { @@ -134,7 +140,6 @@ int main(int argc, char **argv) { if (!arg.compare("-h") || !arg.compare("--help")) { help(); - return 0; } else if (!arg.compare("-v") || !arg.compare("--version")) { std::cout << "mcopy " << VERSION << '\n'; return 0; @@ -148,13 +153,13 @@ int main(int argc, char **argv) { quiet = false; } else if (!arg.compare("-f") || !arg.compare("--format")) { if (argc > i+1) { - format = argv[i++]; + format = argv[++i]; } continue; } } - if (!format.empty()) { + if (!format.compare("")) { std::cerr << "mcopy: You must specify a format.\n"; return 1; }