Robocopy: Always Copies Directory, Even If It's Old or Empty
Robocopy, also known as Robust File Copy, is a command-line file transfer utility available in Windows operating systems. It is a powerful tool that can copy files and directories from one location to another while providing various options to customize the copy process. One feature of Robocopy that is not well-known is that it always copies the directory, even if it's old or empty.
Why Directories Always Get Copied
Robocopy's behavior of always copying the directory is intentional. This feature ensures that the directory structure is maintained even if there are no files to copy. It can be useful when you want to create a mirror image of a directory tree, and you don't want to worry about whether the directories have files or not. This behavior can also be helpful if you accidentally delete a file from the source directory and want to make sure that the directory structure is preserved in the destination directory.
Using Robocopy to Make Backups
Imagine you're using the Windows robocopy command to make backups of your files. You want to exclude a directory that has already been backed up, but you can't seem to get it to work. The problem is that robocopy always copies the directory, even if it's old and empty. To exclude a directory, you need to use the /xd switch, followed by the directory name. Here's an example:
robocopy source_directory destination_directory /mir /xd backup_directoryIn this example, /mir is the switch for mirroring the source directory to the destination directory. The /xd switch excludes the backup directory from being copied. If the backup directory is empty, robocopy still creates it in the destination directory.
Robocopy Options
Robocopy provides several options that can help you customize the copy process. Here are a few:
- /mir: creates a mirror of the source directory in the destination directory.
- /maxage: excludes files older than the specified number of days.
- /minage: includes only files newer than the specified number of days.
- /dcopy: copies directory timestamps.
- /sec: copies file timestamps and security information.
- /log: creates a log file of the copy process.
For a complete list of options, type robocopy /? in a command prompt window.
Robocopy is a powerful file transfer utility that provides many options to customize the copy process. One feature of Robocopy is that it always copies the directory, even if it's old or empty. This feature can be helpful when creating a mirror image of a directory tree or when you want to preserve the directory structure in the destination directory. To exclude a directory, use the /xd switch. Robocopy provides several options to help you customize the copy process.