Scripting or batch file to create folders

Posted on 2008-06-19
Medium Priority
Last Modified: 2012-06-22
I am looking to create a standard folder structure with a prompt for the name of the root folder in a script or a batch file. Also i want to be able to run this on existing folders to fill in the missing folders.
Question by:Bruce_S_C
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 14

Accepted Solution

sungenwang earned 2000 total points
ID: 21825756
Below is a script that will create a series of folders within the root folder selected by the user:

You can modify the Call MyCreateFolder() function to suit your need.


strRootFolder = MyGetFolder("Please select your root folder", "C:\")
If strRootFolder = "" Then WScript.Quit
strRootFolder = strRootFolder & "\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Call MyCreateFolder(strRootFolder & "folder1")
Call MyCreateFolder(strRootFolder & "folder1\folder1a")
Call MyCreateFolder(strRootFolder & "folder1\folder1b")
Call MyCreateFolder(strRootFolder & "folder2")
Call MyCreateFolder(strRootFolder & "folder3")
Function MyCreateFolder(strFolder)
	If Not objFSO.FolderExists(strFolder) Then
	End If
End Function
Function MyGetFolder(strMessage, strRootPath)
	Set objShell = CreateObject("Shell.Application")
	Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, strMessage, NO_OPTIONS, strRootPath)
	On Error Resume Next
	MyGetFolder = objFolder.Self.Path
	On Error Goto 0
End Function

Open in new window


Author Comment

ID: 21825968
Just to be sure this can be run on a current structure and it will not error if the folder is there?
LVL 14

Expert Comment

ID: 21827586
No. These lines will create folder only if it's not there:

      If Not objFSO.FolderExists(strFolder) Then
      End If


Author Comment

ID: 21830704
How would i add in folder permissions?
LVL 14

Assisted Solution

sungenwang earned 2000 total points
ID: 21831819
I am not a network expert, but this solution deals with adding permission to a folder using Microsoft's vbscript XCacls.vbs.


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

801 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