Re: Script to create subdirectories



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: Script to create subdirectories
    ... Then the rest of the script (i.e. the Function that I posted, ... Dim aFolders, newFolder ... ' Splits the various components of the folder name. ...
    (microsoft.public.windows.server.scripting)
  • re: Cannot query Access db on server
    ... put your database in a subfolder named ... and make that folder ... > dim sLName ... >I've searched for this error message in the Knowledge ...
    (microsoft.public.frontpage.programming)
  • RE: VBA Code Question
    ... You don't mention what the error message is. ... FileCopy() will fail if the mdb file is currently open. ... > on here is that the code is reading a folder and taking all the mdbs and ... > Dim FileSys As FileSystemObject ...
    (microsoft.public.access.modulesdaovba)
  • Re: HTML Item properties vs. Regular item properties
    ... I don't use the MSN provider, but AFAIK the date in the default store's is ... OutlookSpy - Outlook, CDO ... as well as the Sent Items folder on the MSN server. ... Dim app As Outlook.Application ...
    (microsoft.public.outlook.program_vba)
  • Re: HTML Item properties vs. Regular item properties
    ... Why would Outlook record different times for the HTTP ... and the default folder? ... Dim app As Outlook.Application ... "Dmitry Streblechenko" wrote: ...
    (microsoft.public.outlook.program_vba)