8

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

3 Answers 3

16

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

3
  • 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/… Feb 23, 2010 at 19:46
  • Cool utility! I preferred the /S option but this did exactly what I wanted.
    – James Cadd
    Feb 23, 2010 at 19:52
  • 1
    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).
    – iokevins
    Jul 4, 2011 at 5:25
0

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.

0

In regards to if xcopy is still available, yes it is in both Windows 7 and Windows 8.1. Not sure about Windows 10. I just used it to move a whole bunch of ISO files to one directory. Use xcopy /? from a command prompt to get a list of available Xcopy commands.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .