Michael
Mon Jan 10 10:16:36 CST 2005
jp wrote:
> Well took me a while but i found some resources, tweaked a bit and now
> i have a functional VBS (WshShell) working version so i felt to share,
> as I found lots of references on GetParentFolderName() and code that
> worked when on its own but when combined with
>
> Set WshShell = CreateObject("Wscript.shell")
>
> nothing would seem to work or gave errors. Additionally I could not
> find anything concise or directly pointing towards this in a script
> fashion using the above.
>
> So hope this helps anyone who has a need to build directory structures
> with a mind to using VBS.
>
How is that different from the CreateFolderPath function I pointed you to?
If you don't want/need a reference to the folder object created then just
change this:
set fo = CreateFolderPath("c:\_temp\this\that")
to this:
Call CreateFolderPath("c:\_temp\this\that")
If you Call a function (as opposed to using it in the RHS of an assignment
statement) that returns a value (a folder object in this case), the returned
value is simply discarded.
>
> Note the DirPath needs to be set like...
>
> DirPath = "H:\dir\dir\sub\sub"
>
>
> --- snipit
> Sub BuildDirectory(ByVal DirPath)
> Dim fso
> Dim strParentDir
>
> Set fso = CreateObject("Scripting.FileSystemObject")
> strParentDir = fso.GetParentFolderName(DirPath)
> ' Make sure strParentDir has a trailing slash to ensure
> ' FSO doesn't think strParentDir is a file instead of a
> ' folder.
> If Right(strParentDir, 1) <> "\" Then
> strParentDir = strParentDir & "\"
> End If
> Do While Not fso.FolderExists(DirPath)
> If fso.FolderExists(strParentDir) Then
> fso.CreateFolder (DirPath)
> Else
> Call BuildDirectory(strParentDir)
> End If
> Loop
> Set fso = Nothing
> Set strParentDir = Nothing
> End Sub
> --- end code
>
>
> jp
>
> On Wed, 5 Jan 2005 16:35:48 -0800, "Michael Harris \(MVP\)" <mikhar at
> mvps dot org> wrote:
>
>> jp wrote:
>>> Thanks - I like the way the code goes, however this still has a
>>> limitation in writing a directory path that doesn't exist if the
>>> path is more than one directory.
>>
>> Google Search
>>
http://groups-beta.google.com/groups?q=createfolderpath%20group:*.scripting
--
Michael Harris
Microsoft.MVP.Scripting