Robocopy/MOVE: Attempt Delete Non-Empty Folders?
Robocopy, or Robust File Copy, is a powerful command-line file copying tool built into Windows operating systems, starting from Windows XP and onwards. It provides a vast array of options and switches, enabling users to customize file copying processes to their specific needs.
Question:
A user ran the following command:
robocopy.exe C:\Users\Greedo D:\SmallComputer\AllImagesVideos *.gif *.bmp *.xcf *.png *.jpg *.jpeg *.cr2 *.tiff /XD .AppData /XF .F .
/MOVE move image files from userDoes Robocopy attempt to delete non-empty folders using the /MOVE switch?
The /MOVESwitch
The /MOVESwitch offered by Robocopy allows users to move files from a source directory to a destination directory, rather than simply copying. When using the /MOVE switch, Robocopy will delete the source files and folders after they have been successfully moved. However, the question remains, does Robocopy attempt to delete non-empty folders?
Non-Empty Folders and Robocopy
Robocopy will not delete non-empty folders by default, even when using the /MOVE switch. Instead, it will copy the contents of the folders to the destination path, while leaving the source folder intact. This is precisely the reason why the /MOVE switch is a much better choice when compared to manually deleting files using the del command after copying, as it helps keep the source folder structure, avoiding any accidental deletions.
Handling Non-Empty Folders
In some cases, it might be desirable to force Robocopy into deleting non-empty folders. While Robocopy does not have this feature built-in, there are a few workarounds:
-
Perform multiple Robocopy runs, where the first run moves the files and the second run is responsible for deleting the empty folders:
robocopy.exe C:\Users\Greedo D:\SmallComputer\AllImagesVideos *.gif *.bmp *.xcf *.png *.jpg *.jpeg *.cr2 *.tiff /MOV /DCOPY:T
robocopy.exe C:\Users\Greedo D:\SmallComputer\AllImagesVideos /L /MINAGE:1 /S /DCOPY:D /purge -
Use a scripting language, like PowerShell or Python, to perform a post-processing task that deletes empty folders from the source directory after the Robocopy operation is complete.