Solved

Script to create standard folder structure

Posted on 2014-10-03
34
161 Views
Last Modified: 2014-12-24
I need a script to be developed which will allow users when they run it on their desktop to create a set of pre-defined folders with in a folder

Below is the actual requirement

* User could run a program that would prompt him for the name of the site.
* The user would then enter the site name details
* The Script would check to ensure that the site did not already exist in the targeted folder,  If it already existed, then
    the script would flag this up with the user and request an alternative or cancel activity.
*  If the details entered did not exist, it would create a folder using the name provided and then create the
    subsequent folder structure within that folder.

Is it possible to create such a script, if so can you please assist me in creating the script.
0
Comment
Question by:Seshadrim
  • 15
  • 13
  • 6
34 Comments
 
LVL 51

Expert Comment

by:Bill Prew
ID: 40360256
So, would the user be entering a full path of the folder to be created?  Or just a folder name, and you have a hard coded predefined base directory it needs to go in?

What is the folder structure to create underneath the new folder they specify?

~bp
0
 

Author Comment

by:Seshadrim
ID: 40360300
Can we provide an option to browse the location of the path where the folder needs to be created? and Yes I have Predefined folders to be created.

Below is the Example.

C:\Data is the location where I need the Sub folders to be create and below are the List of folders that I need to Create
based on the Site the user selects

When User Select as technical as the Site, Below will be the list of folders

/Technical/
/Technical/Drawing Register/
/Technical/Architect/
/Technical/Structural and Civil Engineering/
/Technical/NHBC
/Technical/Land/
/Technical/S106/
/Technical/Miscellaneous/


When user selects as Commercial, The list of folders are

/Commercial/
/Commercial/Sub-contractor/
/Commercial/Supplier/
/Commercial/Plant/
/Commercial/Prelims

The Same way I have another 5 Sites and their folder structures.
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40360979
you can do something like this:

dim rootFolder
rootFolder = InputBox("Enter Root Folder")
dim siteStructure
 siteStructure = InputBox("Enter Site Structure")
Dim oFSO, fullpath
fullpath=rootFolder & "\" & siteStructure
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FolderExists(fullpath) Then
  msgbox "Site already exists"
else
  oFSO.CreateFolder fullpath
  select case lcase(siteStructure)
    case "technical":
      oFSO.CreateFolder fullpath & "\Drawing Register"
      oFSO.CreateFolder fullpath & "\Architect"
      '... create all necessary structure here
    case "commercial":
      oFSO.CreateFolder fullpath & "\Sub-contractor"
      oFSO.CreateFolder fullpath & "\Supplier"
    case "site3":

  end select
End If

Open in new window


also instead of the first input box, you can use the browse for folder dialog from this site.
VBScript Browse for Dialog
0
 

Author Comment

by:Seshadrim
ID: 40394466
Hi, Sorry there is a Change in the requirement. Below Is the updated one

01) User should be able to run a the script , that would prompt him to enter the name of the site.
02) User would then enter the site name details (Ex Building 1, Building 2, Building 3, Etc)
03) The Script would check and ensure that a folder with the specified site name did not already exist in the targeted
       folder (C:\Programfiles\<Application Name>\Folder1) ,  
04) If a folder with the provided site name  already existed, then the script would flag this up to user and request an
       alternative Site Name or an option to  cancel the activity.
05) If the entered folder does not exist, then it would create a set of folders and sub folders under the site name.

Folders agreed are:

/Technical/
/Technical/Drawing Register/
/Technical/Architect/
/Technical/Structural and Civil Engineering/
/Technical/NHBC
/Technical/Land/
/Technical/S106/
/Technical/Miscellaneous/

/Commercial/
/Commercial/Sub-contractor/
/Commercial/Supplier/
/Commercial/Plant/
/Commercial/Prelims/

/Production/
/Production/Call offs/
/Production/Programme/
/Production/Services/
/Production/Construction Specification/
/Production/Reports/
/Production/Meeting minutes/

/Sales/
/Sales/Sales specification/
/Sales/Customer options(exit)/


/Customer Service/
/Customer Service/plot files for the development/
/Customer Service/HA plot files/
/Customer Service/CSM Reports/

/Health and safety/
/Health and safety/Safety reports/
/Health and safety/Newsflashes/
/Health and safety/Non - conformity notices/
/Health and safety/General memorandums/

/Finance/
/Finance/Times/

can you please assist me in creating the script for the above requirement.
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40399529
you can try something like this:
but you have to modify the lines to reflect the right structure
Dim siteStructure
siteStructure = InputBox("Enter Site Structure")
Dim rootFolder, oFSO, fullpath
Dim over As Boolean
over = False
While Not over
  rootFolder = InputBox("Enter Root Folder")
  If Right(rootFolder, 1) = "\" Then
    fullpath = rootFolder & siteStructure
  Else
    fullpath = rootFolder & "\" & siteStructure
  End If
  Set oFSO = CreateObject("Scripting.FileSystemObject")
  If oFSO.FolderExists(fullpath) Then
    If MsgBox("Site already exists, do you want to try another folder?", 36) = 7 Then
      'user replied no
      over = True
      fullpath = ""
    Else
       'user replied yes
       over = False
    End If
  Else
    'folder does not exist
    over = True
  End If
Wend
    
If fullpath <> "" Then
  oFSO.CreateFolder fullpath
  Select Case LCase(siteStructure)
    Case "technical":
      oFSO.CreateFolder fullpath & "\Drawing Register"
      oFSO.CreateFolder fullpath & "\Architect"
      '... create all necessary structure here
    Case "commercial":
      oFSO.CreateFolder fullpath & "\Sub-contractor"
      oFSO.CreateFolder fullpath & "\Supplier"
    Case "architecture":
      oFSO.CreateFolder fullpath & "\Sub-contractor"
      oFSO.CreateFolder fullpath & "\Supplier"
  End Select
  MsgBox "Done"
End If

Open in new window

0
 

Author Comment

by:Seshadrim
ID: 40405294
Hi Balian,

Thanks for your assistance, I copied the above code to notepad and modified the lines to reflect the right structure and stored it with .vbs extension.

When I try to execute the Script I get compilation error as below.

 Compilation-Error-V1.0.PNG
I have also attached the complete Code that I used for your reference.
OneDriveScript-V1.0.txt
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 40405539
I didn't read all the codee, but as far as the error you are getting, you will need to change this line:

Dim over As Boolean


to:

Dim over

~bp
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40405790
as bill stated above, just replace "dim over as boolean" with "dim over".. because in vbscript we don't specify the variable types.. i added that last minute without testing.. and i'm used at writing vb6 code..
0
 

Author Comment

by:Seshadrim
ID: 40406523
Hi Bill ,  Dany

As suggested I have changed the statement "dim over as Boolean" to "dim over" and tried to executed the script, Now I am not getting any compilation errors however the the folders are also not getting created but I get a confirmation message "done" at the last.

Also if I tried Passing a empty value to both the input boxes, and I get an message box stating the Site exists.

I am also thinking if  there would be an option to hard code the root directory instead of user Selection as we did in the previous one. As this may give user an option to create the folders in Wrong Path.

Please assist.
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40407903
here's the full code, tested and modified as requested (the program will now quit if same site exists because root folder is now hardcoded)
just replace the rootfolder (line9) with your own rootfolder and don't forget the backslash at the end:
example: rootfolder="C:\inetput\wwwroot\mysites\"

Dim siteStructure
siteStructure = InputBox("Enter The Site Name")
If Not (LCase(siteStructure) = "technical" Or LCase(siteStructure) = "commercial" Or LCase(siteStructure) = "production" Or LCase(siteStructure) ="sales" Or LCase(siteStructure) = "customer service" Or LCase(siteStructure) = "health and safety" Or LCase(siteStructure) = "finance") Then
 MsgBox ("Invalid Site Name")
 Wscript.Quit
End If
Dim rootFolder, oFSO, fullpath, over
over = False
rootFolder = "C:\boom\" '(the backslash at the end is important)
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FolderExists(rootFolder) Then
  oFSO.CreateFolder rootFolder
End If
fullpath = rootFolder & siteStructure
If oFSO.FolderExists(fullpath) Then
  MsgBox ("Site Already Exists, Quitting..")
  Wscript.Quit
End If
    
If fullpath <> "" Then
  'MsgBox fullpath
  oFSO.CreateFolder fullpath & "\"
  Select Case LCase(siteStructure)
    Case "technical":
      oFSO.CreateFolder fullpath & "\Drawing Register"
      oFSO.CreateFolder fullpath & "\Architect"
      oFSO.CreateFolder fullpath & "\Structural and Civil Engineering"
      oFSO.CreateFolder fullpath & "\NHBC"
      oFSO.CreateFolder fullpath & "\Land"
      oFSO.CreateFolder fullpath & "\S106"
      oFSO.CreateFolder fullpath & "\Miscellaneous"
    Case "commercial":
      oFSO.CreateFolder fullpath & "\Sub-contractor"
      oFSO.CreateFolder fullpath & "\Supplier"
      oFSO.CreateFolder fullpath & "\Plant"
      oFSO.CreateFolder fullpath & "\Prelims"
    Case "production":
      oFSO.CreateFolder fullpath & "\Call Offs"
      oFSO.CreateFolder fullpath & "\Programme"
      oFSO.CreateFolder fullpath & "\Services"
      oFSO.CreateFolder fullpath & "\Construction Specification"
      oFSO.CreateFolder fullpath & "\Reports"
      oFSO.CreateFolder fullpath & "\Meeting minutes"
    Case "sales":
      oFSO.CreateFolder fullpath & "\Sales Specification"
      oFSO.CreateFolder fullpath & "\Customer options(exit)"
    Case "customer service":
      oFSO.CreateFolder fullpath & "\Plot files for the Development"
      oFSO.CreateFolder fullpath & "\HA plot files"
      oFSO.CreateFolder fullpath & "\CSM Reports"
    Case "health and safety":
      oFSO.CreateFolder fullpath & "\Safety reports"
      oFSO.CreateFolder fullpath & "\Newsflashes"
      oFSO.CreateFolder fullpath & "\Non - conformity notices"
      oFSO.CreateFolder fullpath & "\General memorandums"
    Case "finance":
      oFSO.CreateFolder fullpath & "\Times"
  End Select
  MsgBox "Done"
End If

Open in new window

0
 

Author Comment

by:Seshadrim
ID: 40408728
Hi Dany,

Sorry It Didn't work.

I have modified the Line 9 and hard coded the Path to  "C:\Program Files\Microsoft Office 15\root\office15"

When I execute the Script it prompts for a Site name and  ends with an message box stating invalid site name.

I reviewed the Code and If I understood correctly it is Possibly because of the below lines where we have defined the Sites as below in the line 3

If Not (LCase(siteStructure) = "technical" Or LCase(siteStructure) = "commercial" Or LCase(siteStructure) = "production" Or LCase(siteStructure) ="sales" Or LCase(siteStructure) = "customer service" Or LCase(siteStructure) = "health and safety" Or LCase(siteStructure) = "finance") Then
 MsgBox ("Invalid Site Name")
 Wscript.Quit

I also tried executing it with a different path hardcoded and used the site name as defined in Line 3 the execution gets complete but I don't See the folder Structure in the designated folder.

Can you please Check it further.
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40408809
Sitename had to be exactly one of the cases u specified.. Technical, sales...
0
 

Author Comment

by:Seshadrim
ID: 40416168
Hi Dany,

In my Scenario the Site names are the name of the Locations(or) Building names  and We don't have a Defined Location as there are many.

Would it be possible to leave the Site name open and restrict the folder Structures please.
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40416603
Sorry you got me confused!
So u have a root folder, a site name, and a structure? 3 variables to construct your path? Is that correct?
0
 

Author Comment

by:Seshadrim
ID: 40421130
Hi Danny,

Yeah that is right, I have a Root folder Defined, and a Site Name which will be Entered by user during the time of Creation  and then the defined folder structure
0
 

Author Comment

by:Seshadrim
ID: 40421244
The Expected Out come is like a folder to be created with the Site name (to be defined by User during the time of Script Execution) under "C:\Program Files\Microsoft Office 15\root\office15" with the defined folder Structured inside the site folder.

Ex :

C:\Program Files\Microsoft Office 15\root\office15\London

C:\Program Files\Microsoft Office 15\root\office15\London

C:\Program Files\Microsoft Office 15\root\office15\London\Technical
C:\Program Files\Microsoft Office 15\root\office15\London\Technical\Drawing Register
....
....
C:\Program Files\Microsoft Office 15\root\office15\London\Commercial\
C:\Program Files\Microsoft Office 15\root\office15\London\Commercial\Sub-contractor\
....
....
C:\Program Files\Microsoft Office 15\root\office15\London\Production
C:\Program Files\Microsoft Office 15\root\office15\London\Production\Call offs\
....
....
C:\Program Files\Microsoft Office 15\root\office15\London\Sales\
C:\Program Files\Microsoft Office 15\root\office15\London\Sales\Sales specification\
....
....
C:\Program Files\Microsoft Office 15\root\office15\London\Customer Service\
C:\Program Files\Microsoft Office 15\root\office15\London\Customer Service\plot files for the development\
....
....
C:\Program Files\Microsoft Office 15\root\office15\London\Health and safety\
C:\Program Files\Microsoft Office 15\root\office15\London\Health and safety\Safety reports\
....
....
C:\Program Files\Microsoft Office 15\root\office15\London\Finance\
C:\Program Files\Microsoft Office 15\root\office15\London\Finance\Times\
....
....
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40421369
Try This, hope it helps you!
    Dim siteStructure, siteName
    Dim rootFolder, oFSO, fullpath, over
    rootFolder = "C:\boom\" '(the backslash at the end is important)
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    If Not oFSO.FolderExists(rootFolder) Then
      oFSO.CreateFolder rootFolder
    End If
    siteName = InputBox("Enter The Site Name")
    If LCase(siteName) = "cancel" Or LCase(siteName) = "" Then
        MsgBox "invalid site name"
        wscript.quit
    End If
    rootFolder = rootFolder & siteName & "\"
    If Not oFSO.FolderExists(rootFolder) Then
      oFSO.CreateFolder rootFolder
    End If
    siteStructure = InputBox("Enter The Site structure")
    If Not (LCase(siteStructure) = "technical" Or LCase(siteStructure) = "commercial" Or LCase(siteStructure) = "production" Or LCase(siteStructure) = "sales" Or LCase(siteStructure) = "customer service" Or LCase(siteStructure) = "health and safety" Or LCase(siteStructure) = "finance") Then
        MsgBox ("Invalid Site structure")
        wscript.quit
    End If
    over = False
    fullpath = rootFolder & siteStructure
    If oFSO.FolderExists(fullpath) Then
      MsgBox ("Site Already Exists, Quitting..")
      wscript.quit
    Else
      oFSO.CreateFolder fullpath & "\"
    End If
  
    Select Case LCase(siteStructure)
        Case "technical":
            oFSO.CreateFolder fullpath & "\Drawing Register"
            oFSO.CreateFolder fullpath & "\Architect"
            oFSO.CreateFolder fullpath & "\Structural and Civil Engineering"
            oFSO.CreateFolder fullpath & "\NHBC"
            oFSO.CreateFolder fullpath & "\Land"
            oFSO.CreateFolder fullpath & "\S106"
            oFSO.CreateFolder fullpath & "\Miscellaneous"
        Case "commercial":
            oFSO.CreateFolder fullpath & "\Sub-contractor"
            oFSO.CreateFolder fullpath & "\Supplier"
            oFSO.CreateFolder fullpath & "\Plant"
            oFSO.CreateFolder fullpath & "\Prelims"
        Case "production":
            oFSO.CreateFolder fullpath & "\Call Offs"
            oFSO.CreateFolder fullpath & "\Programme"
            oFSO.CreateFolder fullpath & "\Services"
            oFSO.CreateFolder fullpath & "\Construction Specification"
            oFSO.CreateFolder fullpath & "\Reports"
            oFSO.CreateFolder fullpath & "\Meeting minutes"
        Case "sales":
            oFSO.CreateFolder fullpath & "\Sales Specification"
            oFSO.CreateFolder fullpath & "\Customer options(exit)"
        Case "customer service":
            oFSO.CreateFolder fullpath & "\Plot files for the Development"
            oFSO.CreateFolder fullpath & "\HA plot files"
            oFSO.CreateFolder fullpath & "\CSM Reports"
        Case "health and safety":
            oFSO.CreateFolder fullpath & "\Safety reports"
            oFSO.CreateFolder fullpath & "\Newsflashes"
            oFSO.CreateFolder fullpath & "\Non - conformity notices"
            oFSO.CreateFolder fullpath & "\General memorandums"
        Case "finance":
            oFSO.CreateFolder fullpath & "\Times"
    End Select
    MsgBox "Done"

Open in new window

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Seshadrim
ID: 40422047
Hi Dany,

Please correct me if I am wrong

From the above code I understand that we are defining the Site names as below.

If Not (LCase(siteStructure) = "technical" Or LCase(siteStructure) = "commercial" Or LCase(siteStructure) = "production" Or LCase(siteStructure) = "sales" Or LCase(siteStructure) = "customer service" Or LCase(siteStructure) = "health and safety" Or LCase(siteStructure) = "finance") Then
        MsgBox ("Invalid Site structure")

If user Enters any other names apart from the ones in the above lines the script will quit stating its an Invalid Site Name.
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40422080
no, i modified that, the site name is now London
the site structure should be one of the listed structures
0
 

Author Comment

by:Seshadrim
ID: 40422096
So will I be able to enter the any Site name as desired as London is only an Example.
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 40423061
Yes, it prompts for the site, did you try to run it?  The following lines do this:  (not looking for any points, just trying to keep things moving here...)

    siteName = InputBox("Enter The Site Name")
    If LCase(siteName) = "cancel" Or LCase(siteName) = "" Then
        MsgBox "invalid site name"
        wscript.quit
    End If

~bp
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40423588
yes, please try to run the script, it will not do any harm, it will just create folders..
just try with a test root folder like c:\boom\ and play with the script, it will do as requested!
when the script prompts for sitename, put london
when the script prompts for structure, put one of the available structures

if the same structure exists for the same site name it will give you an error.
example:
run using london, and sales --> success
run another time using london, and sales -->fail
run another time using london and technical-->success
0
 

Author Comment

by:Seshadrim
ID: 40435272
Hi Dany / Bill,

I executed the above script with destination folder as C:\Staging and it created the folder, But When I Changed the destination folder to C:\Program Files\Microsoft Office 15\root\office15 it didn't create any folders.

Also now the Script is asking for a Site and a Site Structure, Which is not required as per the new requirement ( Updated on 4th November 2014.)

I just need a Prompt of Site name and then all the folders to be created under the Site name as per the predefined structure.
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 40435345
You will probably need to run it with elevated admin privileges to be able to update within C:\Program Files folder, although not sure why that didn't result in an error message someplace.

~bp
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 40435352
If you only want to enter the "site name", then which "structure" do you want to use to create the folder structure within that site?

~bp
0
 

Author Comment

by:Seshadrim
ID: 40435462
I don't have a Structure now as per the new requirement, Once user enters the Site name I need all the listed folders to be Created in to the location folder.
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 40435838
Okay, it sounds like this simplification of the useful code that Dany posted earlier could meet that need then.

rootFolder = "C:\boom\" '(the backslash at the end is important)

Set oFSO = CreateObject("Scripting.FileSystemObject")

If Not oFSO.FolderExists(rootFolder) Then
  oFSO.CreateFolder rootFolder
End If

siteName = InputBox("Enter The Site Name")
If LCase(siteName) = "cancel" Or LCase(siteName) = "" Then
    MsgBox "invalid site name"
    Wscript.Quit
End If
rootFolder = rootFolder & siteName & "\"
If Not oFSO.FolderExists(rootFolder) Then
  oFSO.CreateFolder rootFolder
End If

oFSO.CreateFolder fullpath & "\Drawing Register"
oFSO.CreateFolder fullpath & "\Architect"
oFSO.CreateFolder fullpath & "\Structural and Civil Engineering"
oFSO.CreateFolder fullpath & "\NHBC"
oFSO.CreateFolder fullpath & "\Land"
oFSO.CreateFolder fullpath & "\S106"
oFSO.CreateFolder fullpath & "\Miscellaneous"
oFSO.CreateFolder fullpath & "\Sub-contractor"
oFSO.CreateFolder fullpath & "\Supplier"
oFSO.CreateFolder fullpath & "\Plant"
oFSO.CreateFolder fullpath & "\Prelims"
oFSO.CreateFolder fullpath & "\Call Offs"
oFSO.CreateFolder fullpath & "\Programme"
oFSO.CreateFolder fullpath & "\Services"
oFSO.CreateFolder fullpath & "\Construction Specification"
oFSO.CreateFolder fullpath & "\Reports"
oFSO.CreateFolder fullpath & "\Meeting minutes"
oFSO.CreateFolder fullpath & "\Sales Specification"
oFSO.CreateFolder fullpath & "\Customer options(exit)"
oFSO.CreateFolder fullpath & "\Plot files for the Development"
oFSO.CreateFolder fullpath & "\HA plot files"
oFSO.CreateFolder fullpath & "\CSM Reports"
oFSO.CreateFolder fullpath & "\Safety reports"
oFSO.CreateFolder fullpath & "\Newsflashes"
oFSO.CreateFolder fullpath & "\Non - conformity notices"
oFSO.CreateFolder fullpath & "\General memorandums"
oFSO.CreateFolder fullpath & "\Times"

MsgBox "Done"

Open in new window

~bp
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40436883
thanks bill for your collaboration, i was away from the computer.. yes, your script should do it!
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40436992
another note:
if your path is:
C:\Program Files\Microsoft Office 15\root\office15

then you have to verify that each level of the paths exist:
C:\Program Files\
C:\Program Files\Microsoft Office 15\
C:\Program Files\Microsoft Office 15\root\

i modified the code, so that it will create all parts of the path if they do not exist..

finally, i also found a small bug in bill's code (he forgot to assign the fullpath variable while cutting from the codes)

so the following code is fully running and tested!

dim rootfolder
rootFolder = "C:\boom\lol\ha ha ha\root\"
Set oFSO = CreateObject("Scripting.FileSystemObject")

if right(rootfolder,1)<>"\" then rootfolder=rootfolder & "\"
If Not oFSO.FolderExists(rootFolder) Then
  dim folders, part, i
  folders=split(rootfolder,"\")
  part=folders(0)
  for i=1 to ubound(folders)
   if len(trim(folders(i)))>0 then
     part = part & "\" & folders(i)
     if not oFSO.FolderExists(part) then 
       oFSO.CreateFolder part
     end if
   end if
  next
End If

siteName = InputBox("Enter The Site Name")
If LCase(siteName) = "cancel" Or LCase(siteName) = "" Then
    MsgBox "invalid site name"
    Wscript.Quit
End If
rootFolder = rootFolder & siteName
If Not oFSO.FolderExists(rootFolder) Then
  oFSO.CreateFolder rootFolder
End If

fullpath = rootFolder

oFSO.CreateFolder fullpath & "\Drawing Register"
oFSO.CreateFolder fullpath & "\Architect"
oFSO.CreateFolder fullpath & "\Structural and Civil Engineering"
oFSO.CreateFolder fullpath & "\NHBC"
oFSO.CreateFolder fullpath & "\Land"
oFSO.CreateFolder fullpath & "\S106"
oFSO.CreateFolder fullpath & "\Miscellaneous"
oFSO.CreateFolder fullpath & "\Sub-contractor"
oFSO.CreateFolder fullpath & "\Supplier"
oFSO.CreateFolder fullpath & "\Plant"
oFSO.CreateFolder fullpath & "\Prelims"
oFSO.CreateFolder fullpath & "\Call Offs"
oFSO.CreateFolder fullpath & "\Programme"
oFSO.CreateFolder fullpath & "\Services"
oFSO.CreateFolder fullpath & "\Construction Specification"
oFSO.CreateFolder fullpath & "\Reports"
oFSO.CreateFolder fullpath & "\Meeting minutes"
oFSO.CreateFolder fullpath & "\Sales Specification"
oFSO.CreateFolder fullpath & "\Customer options(exit)"
oFSO.CreateFolder fullpath & "\Plot files for the Development"
oFSO.CreateFolder fullpath & "\HA plot files"
oFSO.CreateFolder fullpath & "\CSM Reports"
oFSO.CreateFolder fullpath & "\Safety reports"
oFSO.CreateFolder fullpath & "\Newsflashes"
oFSO.CreateFolder fullpath & "\Non - conformity notices"
oFSO.CreateFolder fullpath & "\General memorandums"
oFSO.CreateFolder fullpath & "\Times"

MsgBox "Done"

Open in new window

0
 

Author Comment

by:Seshadrim
ID: 40446124
Hi Danny,

I tried executing to Execute the Script, but It didn't create the folders under "C:\Program Files\Microsoft Office 15\root\office15"

Also It seems like we are missing the actual folder structure, All folders are getting created under without their parent folder.
0
 

Author Comment

by:Seshadrim
ID: 40446126
Also It seems like we are missing the actual folder structure, All folders are getting created under site folder  without their parent folder.
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40446156
Can u just define for one last time, what question do u want the script to ask u.. And the final expected folder structure! Because i tried the script and i thought it solved ur needs.. I guess i am misunderstanding your needs! Also, try to run the script as an administrator because creating folders inside program files needs elevated rights!
0
 

Author Comment

by:Seshadrim
ID: 40469302
Hi Dany,

Apologize for the late reply, I was On vacation.

Here is what the we want

I Want the Script to Question the user for Location Detail, Once The User Enters the Location Details it should create a folder with the Location name provided by user under "C:\Program Files\Microsoft Office 15\root\office15" and below is the folder structure

Ex: "Assume User has Entered His Location as London"

C:\Program Files\Microsoft Office 15\root\office15\London

C:\Program Files\Microsoft Office 15\root\office15\London\Technical
C:\Program Files\Microsoft Office 15\root\office15\London\Technical\Drawing Register
....
....
C:\Program Files\Microsoft Office 15\root\office15\London\Commercial\
C:\Program Files\Microsoft Office 15\root\office15\London\Commercial\Sub-contractor\
....
....
C:\Program Files\Microsoft Office 15\root\office15\London\Production
C:\Program Files\Microsoft Office 15\root\office15\London\Production\Call offs\
....
....
C:\Program Files\Microsoft Office 15\root\office15\London\Sales\
C:\Program Files\Microsoft Office 15\root\office15\London\Sales\Sales specification\
....
....
C:\Program Files\Microsoft Office 15\root\office15\London\Customer Service\
C:\Program Files\Microsoft Office 15\root\office15\London\Customer Service\plot files for the development\
....
....
C:\Program Files\Microsoft Office 15\root\office15\London\Health and safety\
C:\Program Files\Microsoft Office 15\root\office15\London\Health and safety\Safety reports\
....
....
C:\Program Files\Microsoft Office 15\root\office15\London\Finance\
C:\Program Files\Microsoft Office 15\root\office15\London\Finance\Times\
....
....

Also The Script should Warn the user if a folder in specified name is already present on that path and Prompt for an alternate location name or Cancel the execution.

Also is there a Way where we Can Start the Script to run in an elevated mode automatically as users will not have Admin rights.
0
 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
ID: 40470179
Sorry, I don't have access to a Windows7 or Newer Pc, but Try this:
If WScript.Arguments.length =0 Then
  Set objShell = CreateObject("Shell.Application")

  objShell.ShellExecute "wscript.exe", Chr(34) & _
  WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else
	Dim rootFolder, oFSO
	rootFolder = "C:\boom\lol\ha ha ha\root\"
	Set oFSO = CreateObject("Scripting.FileSystemObject")
	
	If Right(rootFolder, 1) <> "\" Then rootFolder = rootFolder & "\"
	If Not oFSO.FolderExists(rootFolder) Then
	  Dim folders, part, i
	  folders = Split(rootFolder, "\")
	  part = folders(0)
	  For i = 1 To UBound(folders)
	   If Len(Trim(folders(i))) > 0 Then
	     part = part & "\" & folders(i)
	     If Not oFSO.FolderExists(part) Then
	       oFSO.CreateFolder part
	     End If
	   End If
	  Next
	End If
	
	Dim proceed, testFolder
	proceed = False
	While Not proceed
	    sitename = InputBox("Enter The Site Name")
	    If LCase(sitename) = "cancel" Or LCase(sitename) = "" Then
	        MsgBox "No Site Name Defined, Script will Quit"
	        Wscript.quit
	    Else
	        testFolder = rootFolder & sitename
	        If oFSO.FolderExists(testFolder) Then
	            If MsgBox("Site " & sitename & " already exists. Do you want to suggest a new name?", 36) = 7 Then
	            	'the user answered No
	                MsgBox "Script will Quit"
	                Wscript.quit
	            End If
	        Else
	            rootFolder = rootFolder & sitename
	            oFSO.CreateFolder rootFolder
	            If oFSO.FolderExists(rootFolder) Then
	                proceed = True
	            Else
	                MsgBox "Unable to Create folder: " & rootFolder
	                Wscript.quit
	            End If
	            proceed = True
	        End If
	    End If
	Wend
	If proceed Then
	    fullpath = rootFolder
	    
	    oFSO.CreateFolder fullpath & "\Drawing Register"
	    oFSO.CreateFolder fullpath & "\Architect"
	    oFSO.CreateFolder fullpath & "\Structural and Civil Engineering"
	    oFSO.CreateFolder fullpath & "\NHBC"
	    oFSO.CreateFolder fullpath & "\Land"
	    oFSO.CreateFolder fullpath & "\S106"
	    oFSO.CreateFolder fullpath & "\Miscellaneous"
	    oFSO.CreateFolder fullpath & "\Sub-contractor"
	    oFSO.CreateFolder fullpath & "\Supplier"
	    oFSO.CreateFolder fullpath & "\Plant"
	    oFSO.CreateFolder fullpath & "\Prelims"
	    oFSO.CreateFolder fullpath & "\Call Offs"
	    oFSO.CreateFolder fullpath & "\Programme"
	    oFSO.CreateFolder fullpath & "\Services"
	    oFSO.CreateFolder fullpath & "\Construction Specification"
	    oFSO.CreateFolder fullpath & "\Reports"
	    oFSO.CreateFolder fullpath & "\Meeting minutes"
	    oFSO.CreateFolder fullpath & "\Sales Specification"
	    oFSO.CreateFolder fullpath & "\Customer options(exit)"
	    oFSO.CreateFolder fullpath & "\Plot files for the Development"
	    oFSO.CreateFolder fullpath & "\HA plot files"
	    oFSO.CreateFolder fullpath & "\CSM Reports"
	    oFSO.CreateFolder fullpath & "\Safety reports"
	    oFSO.CreateFolder fullpath & "\Newsflashes"
	    oFSO.CreateFolder fullpath & "\Non - conformity notices"
	    oFSO.CreateFolder fullpath & "\General memorandums"
	    oFSO.CreateFolder fullpath & "\Times"
	    
	    MsgBox "Done"
	End If
End If

Open in new window


if it doesn't work, then simply use the following code, and right click on the vbs file and select run as administrator!

Dim rootFolder, oFSO
rootFolder = "C:\boom\lol\ha ha ha\root\"
Set oFSO = CreateObject("Scripting.FileSystemObject")

If Right(rootFolder, 1) <> "\" Then rootFolder = rootFolder & "\"
If Not oFSO.FolderExists(rootFolder) Then
  Dim folders, part, i
  folders = Split(rootFolder, "\")
  part = folders(0)
  For i = 1 To UBound(folders)
   If Len(Trim(folders(i))) > 0 Then
     part = part & "\" & folders(i)
     If Not oFSO.FolderExists(part) Then
       oFSO.CreateFolder part
     End If
   End If
  Next
End If

Dim proceed, testFolder
proceed = False
While Not proceed
    sitename = InputBox("Enter The Site Name")
    If LCase(sitename) = "cancel" Or LCase(sitename) = "" Then
        MsgBox "No Site Name Defined, Script will Quit"
        Wscript.quit
    Else
        testFolder = rootFolder & sitename
        If oFSO.FolderExists(testFolder) Then
            If MsgBox("Site " & sitename & " already exists. Do you want to suggest a new name?", 36) = 7 Then
            	'the user answered No
                MsgBox "Script will Quit"
                Wscript.quit
            End If
        Else
            rootFolder = rootFolder & sitename
            oFSO.CreateFolder rootFolder
            If oFSO.FolderExists(rootFolder) Then
                proceed = True
            Else
                MsgBox "Unable to Create folder: " & rootFolder
                Wscript.quit
            End If
            proceed = True
        End If
    End If
Wend
If proceed Then
    fullpath = rootFolder
    
    oFSO.CreateFolder fullpath & "\Drawing Register"
    oFSO.CreateFolder fullpath & "\Architect"
    oFSO.CreateFolder fullpath & "\Structural and Civil Engineering"
    oFSO.CreateFolder fullpath & "\NHBC"
    oFSO.CreateFolder fullpath & "\Land"
    oFSO.CreateFolder fullpath & "\S106"
    oFSO.CreateFolder fullpath & "\Miscellaneous"
    oFSO.CreateFolder fullpath & "\Sub-contractor"
    oFSO.CreateFolder fullpath & "\Supplier"
    oFSO.CreateFolder fullpath & "\Plant"
    oFSO.CreateFolder fullpath & "\Prelims"
    oFSO.CreateFolder fullpath & "\Call Offs"
    oFSO.CreateFolder fullpath & "\Programme"
    oFSO.CreateFolder fullpath & "\Services"
    oFSO.CreateFolder fullpath & "\Construction Specification"
    oFSO.CreateFolder fullpath & "\Reports"
    oFSO.CreateFolder fullpath & "\Meeting minutes"
    oFSO.CreateFolder fullpath & "\Sales Specification"
    oFSO.CreateFolder fullpath & "\Customer options(exit)"
    oFSO.CreateFolder fullpath & "\Plot files for the Development"
    oFSO.CreateFolder fullpath & "\HA plot files"
    oFSO.CreateFolder fullpath & "\CSM Reports"
    oFSO.CreateFolder fullpath & "\Safety reports"
    oFSO.CreateFolder fullpath & "\Newsflashes"
    oFSO.CreateFolder fullpath & "\Non - conformity notices"
    oFSO.CreateFolder fullpath & "\General memorandums"
    oFSO.CreateFolder fullpath & "\Times"
    
    MsgBox "Done"
End If

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
Synchronize a new Active Directory domain with an existing Office 365 tenant
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

21 Experts available now in Live!

Get 1:1 Help Now