Solved

Create SubFolders after Root Folder is created from xls file

Posted on 2008-10-22
3
589 Views
Last Modified: 2012-05-05
Hello, I am trying to create subfolders underneath a root folder. I have say 10000 folders being created fine using the attached code.I am trying to figure out how to have subfolders created under each folder I have created using the excel spreadsheet data.

This is the structure i am looking to acheive.

Clients\10000\
                     10001\
                              SubFolder ( not part of xls data) just a folder that I will name
                              perhaps more subfolders here as well

So my code so far takes the data from xls and creates the 10000 folders i want.Underneath each of these 10000 folders I want to create other folders for each.

The bottom code snippet is what I am thinking but cant seem to get it right... can anyone help at all..


Thanks Very much
   
strComputer = "." 
 

strRoot = "z:\clients\10000\"
 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
 

Set objExcel = CreateObject("Excel.Application")

Set objWorkbook = objExcel.Workbooks.Open("C:\Scripts\Clients10.xls") 

objExcel.Visible = False 
 

i = 1 
 

Do Until objExcel.Cells(i, 1).Value = ""     

    strNewFolderName = objExcel.Cells(i, 1).Value

    
 

 Set objFSO = CreateObject("Scripting.FileSystemObject")

 Set objFolder = objFSO.CreateFolder(strRoot & strNewFolderName) 

	
 

    

 

    i = i + 1

Loop 
 

 objExcel.quit
 

-------------------

Set objFolder=objFSO.GetFolder(strRoot & strFolder)

Set colFolders=objFolder.SubFolders

arrFolders=Array("SubFolder1","SubFolder2","SubFolder3")

 

For Each item In arrFolders

    If objFSO.FolderExists(strRoot & strFolder & "\" & item) Then

        WScript.Echo "Folder " & strRoot & strFolder &_

         "\" & item & " already exists"

    Else

        colFolders.Add item

    End If

Open in new window

0
Comment
Question by:Ottawaya
3 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 250 total points
ID: 22780888
Assuming that I am understanding your intention correctly, this should do it.


Set objFolder=objFSO.GetFolder(strRoot)

Set colFolders=objFolder.SubFolders

arrFolders=Array("SubFolder1","SubFolder2","SubFolder3")

 

For Each objSub in colFolders

    For Each item In arrFolders

        If objFSO.FolderExists(objSub.Path & "\" & item) Then

            WScript.Echo objSub.Path & "\" & item & " already exists"

        Else

            objFSO.CreateFolder objSub.Path & "\" & item

        End If

    Next

Next

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22781216
Hi, perhaps a function like this would help?

Regards,

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")

strPath = "C:\Temp\Folder1\Folder2"

If objFSO.FolderExists(strPath) = False Then CreateLocalDirectoryStructure strPath
 

Sub CreateLocalDirectoryStructure(strPath)

	If Right(strPath, 1) = "\" Then strPath = Left(strPath, Len(strPath) - 1)

	arrBits = Split(strPath, "\")

	strSubPath = arrBits(0)

	If UBound(arrBits) > 0 Then

		For intBit = 1 To UBound(arrBits)

			strSubPath = strSubPath & "\" & arrBits(intBit)

			If objFSO.FolderExists(strSubPath) = False Then objFSO.CreateFolder(strSubPath)

		Next

	End If

End Sub

Open in new window

0
 

Author Closing Comment

by:Ottawaya
ID: 31508932
This is exactly what i was looking for I just appened it to ,y current script and volia.. all folders are there. I was on the right track.nest for loops i guess is the answer. I will ping back when i need more.. I have to now migrate data to these folders.. grr thats going to be a bigger task...

Thanks Much Shift-3
0

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

Title # Comments Views Activity
Shift Rows Down, after copying from one sheet to another 7 46
Check version 13 68
Script is being strange 8 63
Protecting vb6 & .Net code Obfuscation 18 94
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
A short film showing how OnPage and Connectwise integration works.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

914 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

14 Experts available now in Live!

Get 1:1 Help Now