2013-11-21 98 views
0

我有一個變量copyFolderPathc:\images\movies\users\joe\如何使用VBScript創建目錄和子目錄?

我有以下代碼:

If objFSO.FolderExists(copyFolderPath) = False Then 
    Wscript.Echo "Creating: " + copyFolderPath 
    objFSO.createFolder copyFolderPath 
End If 

的問題是,如果不存在,這只是創建joe目錄。我需要的代碼也會創建users,moviesimages目錄,如果它們不存在。

我該怎麼做?

+0

[文件夾複製到另一個路徑得到錯誤(可能重複http://stackoverflow.com/questions/17174284/copying-folder-to-another-路徑得到錯誤) –

回答

0

我結束了使用此功能:

Sub subCreateFolders(strPath) 

    If Right(strPath, 1) <> "\" Then 
     strPath = strPath & "\" 
    End If 

    strNewFolder = "" 
    Do Until strPath = strNewFolder 
     strNewFolder = Left(strPath, InStr(Len(strNewFolder) + 1, strPath, "\")) 

     If objFSO.FolderExists(strNewFolder) = False Then 
     objFSO.CreateFolder(strNewFolder) 
     End If 
    Loop 
End Sub