Windows 7 – Move Files of a Given Extension While Preserving Folder Structure

file managementwindows 7

I'm trying to move only a certain type of files, *.txt, from their current location to another folder. I know that can be done in Windows Explorer with the search feature + drag and drop. However, that flattens the folder structure and all files end up in the target folder. What I would like to do is move all those files but preserve their relative folder structure. So given a source that looks like this:

\Source\One\Test1.txt
\Source\One\Test2.avi
\Source\Two\Test3.txt
\Source\Two\Test4.avi

And the destination folder:

\Destination

I'd like a simple way to move or copy the txt files to attain the following:

\Destination\One\Test1.txt
\Destination\Two\Test3.txt

Best Answer

You can accomplish this using the Robocopy utility. Robocopy is standard in Windows Vista, Windows 7 and Windows Server 2008. If you have a previous version of Windows, you can get it as part of the Windows Resource Kit for your version of Windows. From a command prompt, use the following command and it should take care of your problem:

robocopy c:\source c:\destination /E *.txt

More information about Robocopy

Related Question