Sub test_0208()
' 引用 FileSystemObject 对像(物件)
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Path = ActiveWorkbook.Path & "\"
' 新建第2层文件夹
FSO.CreateFolder (Path & "Test")
' 新建第3层文件夹
FSO.CreateFolder (Path & "Test\L3")
' 新建第4层文件夹
FSO.CreateFolder (Path & "Test\L3\L4")
' 检测文件夹是否存在
If FSO.FolderExists(Path & "Test\L3\L4") Then
Debug.Print "存在"
Else
Debug.Print "不存在"
End If
' 建立文件夹对像
Set FD2 = FSO.GetFolder(Path & "Test")
' 历遍文件夹 FD2 之下层子文件夹
For Each xFD In FD2.SubFolders
Debug.Print xFD.Name
Next
' 历遍文件夹 FD2 之下层文件
For Each xFile In FD2.Files
Debug.Print xFile.Name
Next
End Sub