背景:
需要输出C:\Test 路径下面所有子文件的目录
实现代码:
Set oFso = CreateObject("Scripting.FileSystemObject")
dim a
a=""
msgbox "scanning"
treeIt("c:\Test")
set f=ofso.opentextfile("AllPath.txt",2,true)
f.write a
f.close
msgbox "OK"
Function TreeIt(sPath)
on error resume next
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFso.GetFolder(sPath)
Set oSubFolders = oFolder.Subfolders
Set oFiles = oFolder.Files
For Each oFile In oFiles
a=a & ofile.path & vbcrlf
Next
For Each oSubFolder In oSubFolders
TreeIt(oSubFolder.Path)
Next
End Function
实现结果:
C:\Test\log\AllCase.txt
C:\Test\log\A_log.txt
C:\Test\log\B_log.txt
C:\Test\log\CMiss_log.txt
C:\Test\log\C_log.txt
C:\Test\log\D_log.txt
C:\Test\log\E_log.txt
C:\Test\log\failedCase.txt
C:\Test\log\FCase.txt
C:\Test\log\F_log.txt
C:\Test\log\gg_log.txt
C:\Test\log\G_log.txt
C:\Test\log\last.txt
C:\Test\log\Last_log.txt
C:\Test\log\log.txt
C:\Test\log\log_1.txt
C:\Test\log\log_2.txt
C:\Test\log\Miss.txt
C:\Test\log\Miss_log.txt
C:\Test\log\more_log.txt
C:\Test\log\Y_log.txt
C:\Test\Reference\backup.xlsx