Implements the /MOVE switch, which moves not only the files, but also the directories in the source folder
Signed-off-by: Florian Eder others.meder@gmail.com --- programs/robocopy/main.c | 31 ++++++++++++++++++++++++++++--- programs/robocopy/robocopy.h | 1 + 2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/programs/robocopy/main.c b/programs/robocopy/main.c index 3036776339d..1cfbe65e94b 100644 --- a/programs/robocopy/main.c +++ b/programs/robocopy/main.c @@ -177,6 +177,12 @@ static void parse_arguments(int argc, WCHAR *argv[]) { options.purge_source_files = TRUE; } + /* move - Delete files (including folders) after copying them */ + else if (!wcsicmp(argv[i], L"/move")) + { + options.purge_source = TRUE; + options.purge_source_files = TRUE; + } /* lev - Limit depth of subdirectories */ else if (!wcsnicmp(argv[i], L"/lev:", 5)) { @@ -388,6 +394,19 @@ static BOOL perform_copy(struct robocopy_statistics *statistics)
}
+ /* if move is specified, we delete the empty remaining folders in the source */ + if (options.purge_source) + { + LIST_FOR_EACH_ENTRY_REV(current_path, &paths_source, struct path, entry) + { + /* append relative path to the source to get the absolute path of the source file / directory */ + current_absolute_path = get_combined_path(options.source, current_path->name); + + if (PathIsDirectoryEmptyW(current_absolute_path)) + RemoveDirectoryW(current_absolute_path); + } + } + /* search for extra files (files only in destination) to be able to return the correct exit code */ LIST_FOR_EACH_ENTRY_REV(current_path, &paths_destination, struct path, entry) { @@ -459,9 +478,15 @@ static WCHAR *get_option_string(void) if (options.purge_destination) wcscat(temp_string, L"/PURGE ");
- /* Move files */ - if (options.purge_source_files) - wcscat(temp_string, L"/MOV "); + /* Move files and folders */ + if (options.purge_source) + wcscat(temp_string, L"/MOVE "); + else + { + /* Move files */ + if (options.purge_source_files) + wcscat(temp_string, L"/MOV "); + }
string = wcsdup(temp_string); return string; diff --git a/programs/robocopy/robocopy.h b/programs/robocopy/robocopy.h index e6779248aa5..aa58240d8cc 100644 --- a/programs/robocopy/robocopy.h +++ b/programs/robocopy/robocopy.h @@ -40,6 +40,7 @@ struct robocopy_options { BOOL copy_subdirectories; BOOL copy_empty_subdirectories; BOOL purge_source_files; + BOOL purge_source; BOOL purge_destination; BOOL mirror; };