Re: Script to create subdirectories
- From: QA <QA@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 20 Apr 2006 11:36:02 -0700
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
- Prev by Date: Re: [MSH] gci behavior -
- Next by Date: can WMIC return multiple aliases?
- Previous by thread: Re: [MSH] gci behavior -
- Next by thread: Re: Script to create subdirectories
- Index(es):
Relevant Pages
|