1. 程式人生 > 程式設計 >VBS遞迴建立多級目錄資料夾的方法

VBS遞迴建立多級目錄資料夾的方法

核心程式碼

CreateFolders "d:\jb51test\1\2\3\4\5" 

Function CreateFolders(path)
	Set fso = CreateObject("scripting.filesystemobject")
	CreateFolderEx fso,path
	set fso = Nothing
End Function

Function CreateFolderEx(fso,path)
	If fso.FolderExists(path) Then 
		Exit Function
	End If
	If Not fso.FolderExists(fso.GetParentFolderName(path)) Then
		CreateFolderEx fso,fso.GetParentFolderName(path)
	End If
	fso.CreateFolder(path)
End Function

經過測試執行沒問題

文中的兩個函式連結CreateFolder 方法與GetParentFolderName 方法。