function GetAllFile(FolderPath)
Dim fso,f,s
Dim filecol,foldercol
Set fso = CreateObject("Scripting.FileSystemObject")
Set f=fso.getfolder(FolderPath)
set filecol=f.Files
set foldercol=f.subfolders
print f.Name&vbnewline
for each fo in foldercol
s=s&fo.name
s=s&vbnewline
if (fo.isrootfolder) then
for each fi in filecol
s=s&fi.name
s=s&vbnewline
next
else ???
end if
next
print s
end function
这个方法明显不行 我知道要用递归,可是学VBS时间很短 求帮助啊作者: anuo_363 时间: 2012-1-4 12:46
不用递归吧,这样看看能不能把子文件夹下的文件名弄出来:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\scripts")
Set colFolders = objFolder.SubFolders
For Each folder in colFolders
Set files=folder.Files
For Each file in files
Wscript.echo file.Name
Next
Next作者: Shawn_xiao 时间: 2012-1-4 14:11 回复 2#anuo_363
这个只能输出子文件的,而不能输出更里层文件夹的文件名作者: anuo_363 时间: 2012-1-5 13:29
抱歉,没看清题目,看起来是要递归,修改代码,我自己运行了一下,似乎可行,请测试:
function GetAllFiles(folderPath)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(folderPath)
Set colFiles=objFolder.Files
Set colSubFolders = objFolder.SubFolders
For Each file in colFiles
Wscript.echo file.Name
Next
For Each subFolder in colSubFolders
GetAllFiles(subFolder.Path)
Next
End function