Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

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

share|improve this answer
    
You can add the /MOV option after /E to move the files. You might also want to check out RichCopy, if you're more comfortable with a GUI: technet.microsoft.com/en-us/magazine/… –  ThatGraemeGuy Feb 23 '10 at 19:46
    
Cool utility! I preferred the /S option but this did exactly what I wanted. –  James Cadd Feb 23 '10 at 19:52
    
Thanks Scott; also, to preserve timestamps and such, add "/COPYALL /DCOPY:T ". Note: to use /DCOPY:T, install robocopy version XP026, available via the Robocopy GUI (technet.microsoft.com/en-us/magazine/…). Installing the robocopy gui automatically dumps robocopy.exe into C:\WINDOWS\SYSTEM32. Note: if you have already installed robocopy via the Microsoft Windows Resource Kit, you will need to rename the version in C:\Program Files\Windows Resource Kits\Tools (I renamed it to robocopyXP010.exe). –  schultkl Jul 4 '11 at 5:25
add comment

Is xcopy available?

xcopy c:\*.bat z:\targetdir /s

Works on XP. I don't have Windows 7 available at the moment, but it should work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.