I've been trying for a while now to find an efficient way to compact the large directory trees of more than 10 external hard disks. I'll describe the problem in some detail so as to avoid misunderstanding (hopefully) and save your time. Please bear with me, I'm at a pretty basic level with my DOS commands.

The current structure is:

X: \ [main directory] \ [different directories level 2] \ [different directories level 3] \ [many files and subdirectories]

The desired structure is:

X: \ [main directory] \ [different directories level 2] \ [files and subdirectories]

So I want to take out level 3 in bold. I've been studying and experimenting all the various suggested solutions to similar problems I found on the web, ranging from simple commands to batch files and VBS scripts, but no success.
The fact that the level 3 directories (as well as the level 2 directories) all have different names seems to make matters much more complicated, but I've found a relatively easy manual way (Explorer) to rename all the level 2 directories to the same name. So I can convert the structure in:

X: \ [main directory] \ [different directories level 2] \ [XXX] \ [many files and directories]

With this (hopefully useful) context, over to where I'm stuck. After much experimentation I got the following command almost to work correctly at the command prompt:

for /R %i in ("XXX \ .") do xcopy "%i" "%~pi.." /S /E
[spaces around slash added]

A remaining disfunction is that it copies subdirectories at the lowest level up one level, but for some strange reason not the files contained within these subdirectories. Is there a parameter that solves this?
A much bigger problem, however, is that I have to MOVE the source files, because the hard disks are almost full and unable to hold a copy of all files...

Based on suggestions I read on the forum I turned to ROBOCOPY. The syntax where I got to is:

for /R %i in ("XXX \ .") do robocopy /MOVE /S /E "%i" "%~pi.."
[spaces around slash added]

Unfortunately this doesn't work at the command prompt (nor in Power Shell nor as a batch file, btw, giving different errors in each case). It returns the error

"ERROR 123 (0x0000007B) Accessing Source Directory X:\main directory\different directory level 2\XXX\filename.ext\
The filename, directory name, or volume label syntax is incorrect."

Apparently ROBOCOPY requires different directory/file references than XCOPY. I've been experimenting with slashes, quotes, and asterisks, but I'm stuck... Does anybody have a solution? Thanks a lot!

    Your Answer


    By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

    Browse other questions tagged or ask your own question.