2013-11-21 78 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