Help To create Folder1/Folder2 in Windows using VBScript ( Both the folders not exists before, i mean to create multilevel folders @ a strech.) Help To create Folder1/Folder2 in Windows using VBScript ( Both the folders not exists before, i mean to create multilevel folders @ a strech.) windows windows

Help To create Folder1/Folder2 in Windows using VBScript ( Both the folders not exists before, i mean to create multilevel folders @ a strech.)


You could use this function:

Const PATH = "X:\folder0\folder1\folder2"Set fso = CreateObject("Scripting.FileSystemObject")BuildFullPath PATHSub BuildFullPath(ByVal FullPath)    If Not fso.FolderExists(FullPath) Then        BuildFullPath fso.GetParentFolderName(FullPath)        fso.CreateFolder FullPath    End IfEnd Sub

Or simply call the mkdir command from your script:

Set objShell = CreateObject("Wscript.Shell")objShell.Run "cmd /c mkdir X:\folder1\folder2\folder3"


You must split the full path and create each folder.Example function:

Function CreateFolderRecursive(FullPath)  Dim arr, dir, path  Dim oFs  Set oFs = WScript.CreateObject("Scripting.FileSystemObject")  arr = split(FullPath, "\")  path = ""  For Each dir In arr    If path <> "" Then path = path & "\"    path = path & dir    If oFs.FolderExists(path) = False Then oFs.CreateFolder(path)  NextEnd Function


Late to the show, but the Shell.Application object works for me in XP, as follows ...

with CreateObject("Shell.Application")  set oFolder = .NameSpace("C:\")  if (not oFolder is nothing) then oFolder.NewFolder("a\b\c\d")end with