Copying folders but not files with Robocopy

by Mitch Tulloch [Published on 21 June 2012 / Last Updated on 26 Jan. 2012]

A tip on how you can copy folders but not files using Robocopy

Let's say you have a folder C:\dir1 and within \dir1 you have some files and some folders.  You want to copy the folders but not the files to a different directoy C:\dir2.  How can you do this using Robocopy?

You can do it like this:

for /f "delims=" %f in ('dir/b/ad C:\dir1') do robocopy /e C:\source\%f C:\dir2\%f

Mitch Tulloch is a seven-time recipient of the Microsoft Most Valuable Professional (MVP) award and widely recognized expert on Windows administration, deployment and virtualization. For more tips by Mitch you can follow him on Twitter or friend him on Facebook.

The Author — Mitch Tulloch

Mitch Tulloch is a well-known expert on Windows Server administration and cloud computing technologies. He has published over a thousand articles on information technology topics and has written, contributed to or been series editor for over 50 books.

Latest Contributions

Featured Links