Solved

Scripting or batch file to create folders

Posted on 2008-06-19
6
419 Views
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.
0
Comment
Question by:Bruce_S_C
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
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:
<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
 

Author Comment

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

Expert Comment

by:sungenwang
ID: 21827586
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
 

Author Comment

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

Assisted Solution

by:sungenwang
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.
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/2003_Server/Q_22613039.html

sew
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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