Kae Travis

Create a Nested Folder Structure using VBScript

Description:

The Filesystem Object cannot create a nested folder structure in a single invocation of the CreateFolder method. For example, if we tried executing the following code it would return a ‘Path Not Found’ error unless c:\alkanesolutions\ already exists:

objFSO.CreateFolder “c:\alkanesolutions\test\”

The function below resolves this limitation.

Source:

Technet Forums

Script:

Dim FullPath : FullPath = "c:\alkanesolutions\test\folder"
Dim objFSO : Set objFSO = CreateObject("Scripting.FilesystemObject")
BuildFullPath FullPath
Sub BuildFullPath(ByVal FullPath)
If Not objFSO.FolderExists(FullPath) Then
BuildFullPath objFSO.GetParentFolderName(FullPath)
objFSO.CreateFolder FullPath
End If
End Sub

 

 

Create a Nested Folder Structure using VBScript
Create a Nested Folder Structure using VBScript

Leave a Reply