vbs怎么遍历C盘下所有目录包括子目录下的文件,并且记录其路径到一个文本文件

要求完全使用vbs完成,不使用cmd命令。

Set oFso = CreateObject("Scripting.FileSystemObject")
dim a
a=""
msgbox "点击确定开始扫描c盘,这些需要几分钟的时间"
treeIt("c:\")
set f=ofso.opentextfile("jl.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
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-08-12
这个要求还真是用cmd最简单,一行代码就搞定了。非要用vbs的话也可以。之前就写过。
在这里
http://zhidao.baidu.com/question/212369161.html?oldq=1
里边有个treeit函数,稍微改改里边的代码就可以实现了