如何使用VBScript创建目录和子目录?
我有一个变量如何使用VBScript创建目录和子目录?,vbscript,directory,Vbscript,Directory,我有一个变量copyFolderPath作为c:\images\movies\users\joe\ 我有以下代码: If objFSO.FolderExists(copyFolderPath) = False Then Wscript.Echo "Creating: " + copyFolderPath objFSO.createFolder copyFolderPath End If 问题是,这只会在不存在的情况下创建joe目录。我需要的代码还将创建用户,电影,或者图像目录(
copyFolderPath
作为c:\images\movies\users\joe\
我有以下代码:
If objFSO.FolderExists(copyFolderPath) = False Then
Wscript.Echo "Creating: " + copyFolderPath
objFSO.createFolder copyFolderPath
End If
问题是,这只会在不存在的情况下创建joe
目录。我需要的代码还将创建用户
,电影
,或者图像
目录(如果它们不存在)
我如何才能做到这一点?我最终使用了以下功能:
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
子子创建文件夹(strPath)
如果正确(strPath,1)“\”则
strPath=strPath&“\”
如果结束
strNewFolder=“”
直到strPath=strNewFolder
strNewFolder=Left(strPath,InStr(Len(strNewFolder)+1,strPath,“\”)
如果objFSO.FolderExists(strNewFolder)=False,则
objFSO.CreateFolder(strNewFolder)
如果结束
环
端接头