如何使用VBScript创建目录和子目录?

时间:2013-11-21 16:01:11

标签: vbscript directory

我的变量copyFolderPathc:\images\movies\users\joe\

我有以下代码:

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

问题是,如果该目录不存在,则只创建joe目录。我需要的代码也会创建usersmoviesimages目录,如果它们不存在的话。

我该怎么做?

1 个答案:

答案 0 :(得分: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