Scripting or batch file to create folders

Posted on 2008-06-19
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
  • 3
  • 2
LVL 14

Accepted Solution

sungenwang earned 500 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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