Solved

Script to create subdirectories

Posted on 2013-01-22
4
372 Views
Last Modified: 2013-01-22
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

..........
0
Comment
Question by:P6FER
  • 2
4 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 38805562
Create a template folder in which you create the sub folder structure you want to have per client, for example under "C:\Template":
-subA
----sub1
-------subK
-------subL
----sub2
...

Then use the script below to copy this empty folder structure into all the client folders. It's currently in test mode and will only display the robocopy commands it would normally run. Remove the uppercase "ECHO" in front of robocopy to run it for real.
Try it with a test client structure first.
@echo off
setlocal
set Template=C:\Template
set Target=D:\Clients
for /d %%a in ("%Target%\*.*") do (
	echo Processing '%%~nxa' ...
	ECHO robocopy.exe "%Template%" "%%~a" /e /r:0 /w:0
)
echo Done.

Open in new window

robocopy.exe is a default part of Windows since Vista/W2k8; if you're still on W2k3, it's in the W2k3 Resource Kit Tools:
http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 38805619
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
0
 

Author Comment

by:P6FER
ID: 38805626
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
0
 
LVL 83

Expert Comment

by:oBdA
ID: 38805667
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).
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now