• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

Scripting or batch file to create folders

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.
0
Bruce_S_C
Asked:
Bruce_S_C
  • 3
  • 2
2 Solutions
 
sungenwangCommented:
Below is a script that will create a series of folders within the root folder selected by the user:
<selected_folder>\folder1
<selected_folder>\folder1\folder1a
<selected_folder>\folder1\folder1b
<selected_folder>\folder2
<selected_folder>\folder3

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

sew

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
		objFSO.CreateFolder(strFolder)
	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

0
 
Bruce_S_CAuthor Commented:
Just to be sure this can be run on a current structure and it will not error if the folder is there?
0
 
sungenwangCommented:
No. These lines will create folder only if it's not there:

      If Not objFSO.FolderExists(strFolder) Then
            objFSO.CreateFolder(strFolder)
      End If

sew
0
 
Bruce_S_CAuthor Commented:
How would i add in folder permissions?
0
 
sungenwangCommented:
I am not a network expert, but this solution deals with adding permission to a folder using Microsoft's vbscript XCacls.vbs.
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/2003_Server/Q_22613039.html

sew
0

Featured Post

Industry Leaders: 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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now