Search code examples
dosxcopy

In DOS how to copy one level of directory structory but not subdirectory structure?


In DOS I run this command to copy just the directory structure (including subdirectories):

xcopy c:\sourcedir d:\destdir /T /E

This will copy all subdirectories under sourcedir.

Example these directories exist:

c:\sourcedir 
c:\sourcedir\level1
c:\sourcedir\level2
c:\sourcedir\level2\levelA 
c:\sourcedir\level3
c:\sourcedir\level3\levelB 
c:\sourcedir\level3\levelC

In above command it would create:

d:\destdir
d:\destdir\level1
d:\destdir\level2
d:\destdir\level2\levelA
d:\destdir\level3
d:\destdir\level3\levelB
d:\destdir\level3\levelC

What I only want created is these:

d:\destdir
d:\destdir\level1
d:\destdir\level2
d:\destdir\level3

I am really just looking for a one-liner command. If that can't be done, I can live with one-liner I have, it just takes 5 minutes instead of the few seconds I was looking for.

Thanks for any help...


Solution

  • for /d %F in ("c:\sourcedir\*") do md "d:\destdir\%~nxF"
    

    If used in a batch file then double up percents (%%F, %%~nxF)