GetParentFolderName 方法
返回字符串,該字符串包含指定的路徑中最后一個文件或文件夾的父文件夾。
object.GetParentFolderName(path)
參數
object
必選項。應為 FileSystemObject 的名稱。
path
必選項。指定路徑,要返回文件或文件夾的父文件夾名。
說明
如果 path 參數指定的文件或文件夾無父文件夾,則 GetParentFolderName 方法返回零長度字符串 ("")。
下面例子舉例說明如何使用 GetParentFolderName 方法:
Function GetTheParent(DriveSpec)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
GetTheParent = fso.GetParentFolderName(Drivespec)
End Function
注意 GetParentFolderName 方法只能對提供 path 的字符串起作用。它不能試圖分析一個路徑,也不能檢查指定路徑是否存在。
更詳細的可以參考這篇文章:https://www.jb51.net/shouce/vbs/vsmthGetParentFolderName.htm
給大家分享一個
VBS腳本遞歸創建多級(分級)目錄文件夾
CreateFolders "d:\ftptest\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
主要是使用了遞歸調用的原理實現逐步目錄創建。