用VBS实现查找一个路径下面所有子目录的路径

背景:

需要输出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"

扫描二维码关注公众号,回复: 1152653 查看本文章

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




猜你喜欢

转载自blog.csdn.net/johnny_timmy/article/details/80409160