Link to home
Start Free TrialLog in
Avatar of P6FER
P6FER

asked on

Script to create subdirectories

Hi experts,
I use about  1000 directories for my documents etc. but now I want to create sub-directories in each one. Thanks for the help

I have :

client1
client2
client3
...

And i want :

client1
-subA
----sub1
-------subK
-------subL
----sub2
-------subM
-------subN
----sub3
-------subO
-------subP
-subB
----sub1
-------subW
-------subX
----sub2
-------subY
-------subZ

client2
-subA
----sub1
-------subK
-------subL
----sub2
-------subM
-------subN
----sub3
-------subO
-------subP
-subB
----sub1
-------subW
-------subX
----sub2
-------subY
-------subZ

..........
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

Here's a reasonable approach.  Change the BaseDir to the directory that contains all the client folders.  Then run.

@echo off
setlocal

set BaseDir=c:\temp
set NewDirs="subA\sub1\subK",^
            "subA\sub1\subL",^
            "subA\sub2\subM",^
            "subA\sub2\subN",^
            "subA\sub3\subO",^
            "subA\sub3\subP",^
            "subB\sub1\subW",^
            "subB\sub1\subX",^
            "subB\sub2\subY",^
            "subB\sub2\subZ"

for /D %%D in ("%BaseDir%\*.*") do (
  for %%N in (%NewDirs%) do (
    md "%%~D\%%~N"
  )
)

Open in new window

~bp
Avatar of P6FER

ASKER

Just perfect obda. :-)
You just have to change :
for /d %%a in ("%Target%\*.*") do (

Open in new window

to :
for /d %%a in ("%Target%*.*") do (

Open in new window

Thank you
Only if you're setting Target to a mask including a part of the actual client folder name, like "D:\Clients\Client*.*"; Target was supposed to point to the root folder containing the client1, client2, ... folders (guess I should have mentioned that).