I would like to know how to copy all folders to a new location, but I want only to include the folders themselves -- nothing that is inside of them (so, no subfolders, and no files). Is this possible?
Also, related to this, is there also a way to copy all folders, and also subfolders within those folder, but only 1-level deep (so only direct child folders, not children within the children), and still without any files copied.
I'm open to doing this in any way -- command line, or via a utility.
3 Answers
Use the Microsoft utility robocopy.
robocopy SOURCE_FOLDER DEST_FOLDER /E /LEV:1 /XF * Options:
/ECopy Subfolders, including Empty Subfolders/LEV:1Only copy the top n LEVels of the source tree./XF *eXclude Files matching given names/paths/wildcards.
Source:
1Just to add to Steven's answer, it seems that if you want all the folders within folder X, you'll need to specify folder X as the source and then use /LEV:2, not /LEV:1 (I'm guessing /LEV:1 is just folder X). This is what worked for me just now.
(Would've added this as a comment in reply to Steven's answer, but I don't have the privileges (low reputation).
0Using a command line, if you want to copy just empty folders, that is creating the folders on a new location say somewhere on c:...:
set newlocation=c:\...
@for /f "tokens=3,4" %i in ('dir') do @if "%i" equ "<DIR>" if "%j" neq "." if "%j" neq ".." mkdir %newlocation%\%jIf you want to go one level deep, it's to repeat the for loop once again:
@for /f "tokens=3,4" %i in ('dir') do @if "%i" equ "<DIR>" if "%j" neq "." if "%j" neq ".." mkdir %newlocation%\%j && for /f "tokens=3,4" %u in ('dir %j') do @if "%u" equ "<DIR>" if "%v" neq "." if "%v" neq ".." mkdir %newlocation%\%j\%vNote that if you want to put this into a batch file, replace all % by %%.