I was asked to provide a script to help someone else with creating a folder tree during a software installation. I explained that it’s “one line of code” when using a .BAT/.CMD script with “mkdir x:\folder\folder\folder”, but I got the hand in the face, followed by “we need it to be VBscript, not DOS”. I said “whatever” and cranked out the following hamburger pile. I hope it’s of use to someone else…
rootPath = "c:\program files"
folderPath = "vendorname\appname\folder123"
fpath = rootPath & "\" & folderPath
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(rootPath) Then
tmp = rootPath
For each s in Split(folderPath, "\")
tmp = tmp & "\" & s
If fso.FolderExists(tmp) Then
wscript.echo "exists: " & tmp
Else
wscript.echo "creating: " & tmp
fso.CreateFolder(tmp)
End If
Next
Else
wscript.echo "fail: root path not found = " & rootPath
End If
No comments:
Post a Comment