Windows batch command to move all folders in a directory with exceptions

William Owen picture William Owen · Sep 18, 2011 · Viewed 27k times · Source

I am trying to write a Windows Batch file that will allow me to move all directories within a given source directory into a target directory that exists within that source directory.

Obviously my move command with need to only apply to directories and also exclude the target directory from being processed.

Is this possible with a Windows batch command?

Answer

Alex K. picture Alex K. · Sep 18, 2011

Robocopy (present in recent versions of windows or downloadable from the WRK) can do this, just use the /xd switch to exclude the target directory from the copy;

robocopy c:\source\ c:\source\target\ *.* /E /XD c:\source\target\ /move