Solved

Script to create subfolders

Posted on 2013-05-15
5
311 Views
Last Modified: 2013-05-15
I need to create a script that I can run on a file share that will create a specific subfolder in the same location for all folders. vbscript...batch...powershell all are good

Currently the share is setup like below

h:\
h:\year folder (folders are 1965, 1966,1967... up to 2013
h:\year\Building(building folders are named with last 2 year digits then 3 digits sequentially...65001,65002,97001,97135, 12001,12005 and so on).
We have literally thousands of building folders, I need to be able to create a folder called DST off the root of all building folders

Thanks in advance for all help!
0
Comment
Question by:smithandandersen
  • 2
  • 2
5 Comments
 
LVL 83

Expert Comment

by:oBdA
ID: 39168307
That's a one-liner in a command prompt; it's currently in test mode and will only display the "md" commands it would normally run. To run it for real, remove the uppercase ECHO in front of "md":
for /L %y in (1965, 1, 2013) do @for /d %b in ("H:\%y\Building?????") do @(ECHO md "%b\DST")

Open in new window

And if you insist on a script, you only need to double up on the percent signs And we can make it look a bit more elegant:
@echo off
for /L %%y in (1965, 1, 2013) do (
	for /d %%b in ("H:\%%y\Building?????") do (
		ECHO md "%%b\DST"
	)
)

Open in new window

0
 
LVL 7

Expert Comment

by:BT15
ID: 39168621
in powershell

#this should get all directories with the name Building
get-childitem h:\ -recurse | ? {($_.name -like "Building*") -and ($_.attributes -eq "directory")} | % {

$outpath = $_.fullname + '\DST'

md $outpath

}
0
 
LVL 6

Author Comment

by:smithandandersen
ID: 39168770
Hi guys
my issue is I dont have any folders called building. As I mentioned in my post...the building folders are named like 65008, 72154, 99001 so the file path would be

h:\2013\13001

Have a look at the png
I need a dst folder off the root in every subfolder under each year
H-drive.PNG
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 39168812
Same difference, only a bit less to type; just remove the "Building" in my commands above, so that only the "?????" remain.
for /L %y in (1965, 1, 2013) do @for /d %b in ("H:\%y\?????") do @(ECHO md "%b\DST")

Open in new window

@echo off
for /L %%y in (1965, 1, 2013) do (
	for /d %%b in ("H:\%%y\?????") do (
		ECHO md "%%b\DST"
	)
)

Open in new window

0
 
LVL 6

Author Closing Comment

by:smithandandersen
ID: 39168901
cant believe how efficient that was...
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell / new-object PSObject rows 2 344
Batch File to find and replace a string 15 111
ROBOFTP UNZIP 1 39
Interactive Script in Scheduled Task not running 8 28
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

786 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