How can VBScript create multiple folders in a path, like the MkDir command?
By Unknown | Labels: folder, fso, vbscript, WScript, wshThis is a repost of Jerold Schulman's article on Windowsitpro.com: REF
MakeDir.vbs contains:
dim objArguments, Obj
Set objArguments = Wscript.Arguments
If WScript.Arguments.Count = 0 then
Wscript.Echo "Syntax: cscript //nologo MakeDir.vbs FolderPath"
Wscript.Quit
End If
Obj = objArguments(0)
X = MakeDir(Obj)
Wscript.Quit
Function MakeDir (strPath)
Dim strParentPath, objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
strParentPath = objFSO.GetParentFolderName(strPath)
If Not objFSO.FolderExists(strParentPath) Then MakeDir strParentPath
If Not objFSO.FolderExists(strPath) Then objFSO.CreateFolder strPath
On Error Goto 0
MakeDir = objFSO.FolderExists(strPath)
End Function
0 comments: