Solved

Script to create subdirectories

Posted on 2013-01-22
4
379 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 53

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

17 Experts available now in Live!

Get 1:1 Help Now