Create multiple folders by merging two VBS codes

85 Views Asked by At
'I have 2 scripts but could not combine them


'create multiple folders script:

Dim objFSO, objFolder, strDirectory, i 
strDirectory = "C:\Users\test\Desktop\"
Set objFSO = CreateObject("Scripting.FileSystemObject") 
i = 1  ''
While i < 150 
    Set objFolder = objFSO.CreateFolder(strDirectory & i) 
    i = i+1 
    ''WScript.Quit ''
Wend 


'desktop path script

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
wscript.echo(strDesktop)

I want the code to automatically find the desktop path and then create the folders, some one help me please ?

1

There are 1 best solutions below

0
GuidedHacking On

To get the desktop folder path string and create a sub directory you can do this:

Set objShell = Wscript.CreateObject("Wscript.Shell")
strPath = objShell.SpecialFolders("Desktop")

Dim objFso
Set objFso = WScript.CreateObject("Scripting.FileSystemObject")

If Not objFso.FolderExists(strPath + "\NewFolder") Then
objFso.CreateFolder strPath + "\NewFolder"