Recursively Copy, Delete, and Move Directories in Windows

Advertisement

Advertisement

Introduction

If you need to copy an entire directory to a new destination in Windows, you can use xcopy. This guide will show you how to use xcopy to recursively copy a directory, all of its subdirectories, and include hidden files. We will also look at how to remove a directory with rmdir and move a directory with move.

Recursively copy a directory

The command to recursively copy in Windows command prompt is:

xcopy some_source_dir new_destination_dir\ /E/H

It is important to include the trailing slash \ to tell xcopy the destination is a directory.

The two options are also important:

  • /E - Copy all subdirectories
  • /H - Copy hidden files too (e.g. .git)

You can see more options by running:

xcopy /?

Move a directory

To simply move a directory instead of copying it, use the move command.

move some_directory new_directory_name

Remove a directory

To remove a directory and all of its contents, you can use rmdir.

rmdir some_directory /Q/S

The important options are:

  • /Q - Do not prompt with "Are you sure?"
  • /S - Delete all contents and sub-directories

Run rmdir /? for more help.

Conclusion

You should now know how to recursively copy a directory including hidden files in Windows using xcopy, delete a directory using rmdir, and move a directory using move.

Advertisement

Advertisement