Skip to content

Commit

Permalink
Fixed negative width bug when files are 0 and added copy&delete mode
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkStar1997 committed Mar 12, 2022
1 parent ae22f79 commit b185f02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 10 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ int main()
std::string output = config_data["output_dir"];
std::vector<std::string> extensions = config_data["extensions"];
std::string mode = config_data["mode"];
if(mode != "copy" && mode != "move")
throw std::runtime_error("Incorrect option for mode. Available options: [copy, move]");
if(mode != "copy" && mode != "move" && mode != "copy&delete")
throw std::runtime_error("Incorrect option for mode. Available options: [copy, move, copy&delete]");
fmt::print("Selected mode: {}\n", mode);

size_t count = 0, duplicates = 0;
Expand All @@ -97,6 +97,9 @@ int main()
if(std::filesystem::is_regular_file(dir_entry.path()) && std::find(extensions.begin(), extensions.end(), dir_entry.path().extension()) != extensions.end())
file_count++;
fmt::print("Files to be operated: {}\n", file_count);

if(file_count == 0)
exit(0);

std::vector<std::string> duplicate_list; duplicate_list.reserve(file_count);
std::vector<std::pair<std::string, std::string>> renamed_list; renamed_list.reserve(file_count);
Expand Down Expand Up @@ -155,6 +158,11 @@ int main()
std::filesystem::copy_file(dir_entry.path(), output_file);
else if(mode == "move")
std::filesystem::rename(dir_entry.path(), output_file);
else if(mode == "copy&delete")
{
std::filesystem::copy_file(dir_entry.path(), output_file);
std::filesystem::remove(dir_entry.path());
}
count++;
}
}
Expand Down
12 changes: 7 additions & 5 deletions rmg_config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"input_dir": "PlayerVisualization",
"output_dir": "roha",
"extensions": [".cpp", ".json", ".txt"],
"input_dir": "/run/user/1000/gvfs/mtp:host=SAMSUNG_SAMSUNG_Android_RZ8N906GZPH/Phone/SendAnywhere",
"output_dir": "/run/media/rohan/Media/Photos",
"extensions": [".JPG", ".jpeg"],

// Valid options are "copy" and "move"
// copy means files are copied from input_dir to output_dir while move means files are moved
// Valid options are "copy", "move", "copy&delete"
// copy means files are copied from input_dir to output_dir
// move means files are moved
// copy&delete means the file is copied from input_dir and then deleted; this mode is a fallback to be selected when move fails

"mode": "copy"
}

0 comments on commit b185f02

Please # to comment.