Saves and displays the number of files / directories copied or moved
Signed-off-by: Florian Eder others.meder@gmail.com --- programs/robocopy/main.c | 19 ++++++++++++++++--- programs/robocopy/robocopy.h | 7 +++++++ programs/robocopy/robocopy.rc | 1 + 3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/programs/robocopy/main.c b/programs/robocopy/main.c index b9356b4d104..3bd8b784796 100644 --- a/programs/robocopy/main.c +++ b/programs/robocopy/main.c @@ -321,7 +321,7 @@ static void get_file_paths_in_folder(WCHAR *directory_path, struct list *paths, } }
-static BOOL perform_copy(void) +static BOOL perform_copy(struct robocopy_statistics *statistics) { struct list paths_source; struct path *current_path; @@ -358,12 +358,14 @@ static BOOL perform_copy(void) /* Create the directory path and then create the directory itself */ if (!create_directory_path(target_path)) output_error(STRING_ERROR_WRITE_DIRECTORY, GetLastError(), strip_path_prefix(target_path)); + else statistics->copied_directories++; } else { if (copy_or_move_file(current_absolute_path, target_path, options.purge_source_files)) { output_message(options.purge_source_files ? STRING_MOVE_FILE : STRING_CREATE_FILE, strip_path_prefix(target_path)); + statistics->copied_files++; } }
@@ -425,6 +427,10 @@ static void print_header(void)
int __cdecl wmain(int argc, WCHAR *argv[]) { + struct robocopy_statistics statistics; + int exit_code; + WCHAR dirs_copied[64], files_copied[64]; + parse_arguments(argc, argv);
/* If no file filters are set, set *.* to include all files */ @@ -444,8 +450,15 @@ int __cdecl wmain(int argc, WCHAR *argv[]) return ROBOCOPY_ERROR_NO_FILES_COPIED; }
- if (!perform_copy()) + memset(&statistics, 0, sizeof(struct robocopy_statistics)); + if (!perform_copy(&statistics)) return ROBOCOPY_ERROR_NO_FILES_COPIED;
- return ROBOCOPY_NO_ERROR_FILES_COPIED; + swprintf(dirs_copied, ARRAY_SIZE(dirs_copied), L"%u", statistics.copied_directories); + swprintf(files_copied, ARRAY_SIZE(files_copied), L"%u", statistics.copied_files); + output_message(STRING_STATISTICS, dirs_copied, files_copied); + + exit_code = ROBOCOPY_NO_ERROR_NO_COPY; + if (statistics.copied_files) exit_code += ROBOCOPY_NO_ERROR_FILES_COPIED; + return exit_code; } \ No newline at end of file diff --git a/programs/robocopy/robocopy.h b/programs/robocopy/robocopy.h index b7f5c3db89c..6beac9dbc64 100644 --- a/programs/robocopy/robocopy.h +++ b/programs/robocopy/robocopy.h @@ -42,7 +42,13 @@ struct robocopy_options { BOOL purge_source_files; };
+struct robocopy_statistics { + UINT copied_directories; + UINT copied_files; +}; + /* Exit codes */ +#define ROBOCOPY_NO_ERROR_NO_COPY 0 #define ROBOCOPY_NO_ERROR_FILES_COPIED 1 #define ROBOCOPY_ERROR_NO_FILES_COPIED 16
@@ -57,6 +63,7 @@ struct robocopy_options { #define STRING_ERROR_READ_DIRECTORY 1011 #define STRING_ERROR_WRITE_DIRECTORY 1012 #define STRING_ERROR_WRITE_FILE 1014 +#define STRING_STATISTICS 1018 #define STRING_CREATE_DIRECTORY 1019 #define STRING_CREATE_FILE 1022 #define STRING_MOVE_FILE 1024 \ No newline at end of file diff --git a/programs/robocopy/robocopy.rc b/programs/robocopy/robocopy.rc index b4a6f8ab218..b12501017e2 100644 --- a/programs/robocopy/robocopy.rc +++ b/programs/robocopy/robocopy.rc @@ -35,6 +35,7 @@ STRINGTABLE STRING_ERROR_READ_DIRECTORY, "[%1] Error %2 (%3) occurred reading directory "%4":\n%5\n" STRING_ERROR_WRITE_DIRECTORY, "[%1] Error %2 (%3) occurred writing directory "%4":\n%5\n" STRING_ERROR_WRITE_FILE, "[%1] Error %2 (%3) occurred writing file "%4":\n%5\n" + STRING_STATISTICS, "\n Copied %1 directories and %2 files\n" STRING_CREATE_DIRECTORY, " Created Dir: %1\n" STRING_CREATE_FILE, " Copied File: %1\n" STRING_MOVE_FILE, " Moved File: %1\n"