Re: Script to create subdirectories



Thank you so much... it works great!!!

"maximillianx" wrote:

You need to call the function, not alter the function :)

So your script should have a line like this:

MakeSureDirectoryTreeExists("C:\www.hits\corphit.iacnet.com\cgi-bin")

Then the rest of the script (i.e. the Function that I posted, but leave the
Function statement as-is (i.e. Function
MakeSureDirectoryTreeExists(dirName) )

Regards,
Rob


"QA" <QA@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A01D322B-4F26-4F6E-9E8A-BEAD8AD4CE63@xxxxxxxxxxxxxxxx
Maximillian:

Thank you so much for taking the time to send me the script. It's looks
very
complete!
I tried it and I'm getting an error message at this line:

Function MakeSureDirectoryTreeExists(dirName)

where I replaced dirName with
("C:\www.hits\corphit.iacnet.com\cgi-bin")

I tried with and without quotes and still fails at this line.

Thanks in advance for your help!

"maximillianx" wrote:

Here's a function that I use exclusively to create folders structures.
However, my function is VBScript, and I almost clicked 'send' before I
realized that your function is VB, which isn't quite the same thing! :) .

Regarding this function, I didn't write it, but it has saved me so many
times I can't even count them all. I did however modify it slightly to
accomodate long directory paths and UNCs:

' The MakeSureDirectoryTreeExists Function

' Although the FSO model doesn't have a direct method to create nested
' folders, you can use the following function. This VBScript function
uses
' VBScript's Split function to break the folder path it receives into
' components. From those components, the MakeSureDirectoryTreeExists
' creates subfolders, one at a time. Because the function checks for the
' folder's existence before proceeding, you can pass it any tree, as long
as
' you make sure that, after it returns, the entire tree exists as you
specified.
' With the MakeSureDirectoryTreeExists function, a call such as
' MakeSureDirectoryTreeExists "C:\one\two\three"
' is legitimate and won't result in an error message.

Function MakeSureDirectoryTreeExists(dirName)
Dim aFolders, newFolder
dim delim
' Creates the FSO object.
Set fso = CreateObject("Scripting.FileSystemObject")

' Checks the folder's existence.
If Not fso.FolderExists(dirName) Then

' Splits the various components of the folder name.
If instr(dirname,"\\") then
delim = "-_-_-_-"
dirname = replace(dirname,"\\",delim)
End if

aFolders = split(dirName, "\")

If InStr(dirname,delim) Then
dirname = replace(aFolders(0),delim,"\\")
End if

' Obtains the drive's root folder.
newFolder = fso.BuildPath(dirname, "\")

' Scans each component in the array, and create the appropriate folder.
For i=1 to UBound(aFolders)
If IntDebug = 1 Then
strTempVar = "Checking to see if " & newfolder _
& " exists..."
End If
newFolder = fso.BuildPath(newFolder, aFolders(i))


If Not fso.FolderExists(newFolder) Then
If IntDebug = 1 Then
strTempVar = "Creating " & newfolder
End If
fso.CreateFolder newFolder
err.clear
End If
Next
End If
End Function


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

"QA" <QA@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:65CE35B0-FCC6-4309-86FE-1E814C7A2150@xxxxxxxxxxxxxxxx
I found this vbs script that creates a directory & subdirectories. The
final
directory structure should look like: c:\www\hits\xxx.yyy.zzz\cgi-bin.
I'm getting an error message on line "Public Class CreateSubTest"
indicating "Expected Identifier".

If anyone has other suggestions to accomplish this, any help is
appreciated.


************************************************
Imports System
Imports System.IO

Public Class CreateSubTest

Public Shared Sub Main()
' Make a reference to a directory.
Dim di As New DirectoryInfo("www")

' Create the directory only if it does not already exist.
If di.Exists = False Then
di.Create()
End If

' Create a subdirectory in the directory just created.
Dim dis As DirectoryInfo = di.CreateSubdirectory("hits")
' Create a subdirectory in the directory just created.
Dim dis As DirectoryInfo = di.CreateSubdirectory("xxx.yyy.com")
' Create a subdirectory in the directory just created.
Dim dis As DirectoryInfo = di.CreateSubdirectory("cgi-bin")
' Process that directory as required.
' ...
End Sub 'Main
End Class 'CreateSubTest






.



Relevant Pages

  • Re: map web folder
    ... I ran through the creation script one time today and it worked like a charm! ... until then here is the script to create a web folder ... Dim iRes, jRes, MT, TT ... bString = bString & Chr ...
    (microsoft.public.scripting.wsh)
  • Re: Create OU and users with VBS and Excel
    ... OU each user should be created in, and what profile path to use. ... However, if you want to automate this all in one script, read the OU ... cacls command to assign privileges for the folder to the new user object. ... Dim objRootLDAP, objContainer, objUser, objShell ...
    (microsoft.public.scripting.vbscript)
  • Re: Script to create subdirectories
    ... I tried it and I'm getting an error message at this line: ... Dim aFolders, newFolder ... ' Splits the various components of the folder name. ...
    (microsoft.public.windows.server.scripting)
  • Re: help with error checking in code NEWBIE
    ... Below is the entire script again with an error check for creating the ... in each folder on your C Drive? ... Dim intFOL ...
    (microsoft.public.scripting.vbscript)
  • Re: help with error checking in code NEWBIE
    ... intFOL = intFOL + 1 ... ' folder already exists ... Next at the top of a script. ... Dim intFOL ...
    (microsoft.public.scripting.vbscript)