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

前端 未结 4 846
既然无缘
既然无缘 2020-12-11 01:39

I have created folders using my VBscript. when i give a folder path, the script is creating only the last folder, if the last but one folder does not exists, it will fail...

4条回答
  •  情话喂你
    2020-12-11 01:59

    You could use this function:

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

    Or simply call the mkdir command from your script:

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

提交回复
热议问题