小弟用FindFirstFile,FindNextFile,和FindClose这三个API,写了一个函数
FindFiles(strFolder as String),查找strFolder下的所有文件,当我递归调用FindFiles时出现了堆栈溢出,请问各位大大怎么解决这个问题
还有无更好的办法/算法,检索文件
谢谢以下是基本思路Sub FindFiles(strFolder as String)
..............
.............If this is a dir
strFolder=strFolder+dir
FindFiles(strFolder)
else
collectionFiles.add File.name or strFolder+File.name
....................
End Sub
FindFiles(strFolder as String),查找strFolder下的所有文件,当我递归调用FindFiles时出现了堆栈溢出,请问各位大大怎么解决这个问题
还有无更好的办法/算法,检索文件
谢谢以下是基本思路Sub FindFiles(strFolder as String)
..............
.............If this is a dir
strFolder=strFolder+dir
FindFiles(strFolder)
else
collectionFiles.add File.name or strFolder+File.name
....................
End Sub
解决方案 »
- VB中 sendkeys 输入出右功能键杂输出比如 ctrl 直接输出 sendkeys {ctrl}在的杂输出
- 请教VB高手....想跳楼了。.
- 三个神话的破灭 VB程序员未来究竟在哪?
- 请问用printform打印的时候,可不可以预览啊?(最好有代码)
- 問一個簡單的問題:ByVal,byRef兩個關鍵字的用處的詳細說明。
- 本地可连,远程不能连?求助啊,高手快来.....
- 如何使VB程序调用大量的public function 而不占用太多的资源?
- 50分求救!!!!!请问,如何用VB新建一个ACCESS的表啊,字段为fld1,fld2,fld3,fld4
- 如何使用vb制作程序 截取“万象网管”中已登陆会员的卡号。
- 请问 rs.Open sqlstr, con, 1, 3 怎么获得更新了几条数据库记录?
- 如何用VB读取一个csv格式的文件~~~~
- 如何判断一个控件数组中的控件已经加载
Public Sub SeachFile(ByVal strPath As String)
Dim Fso As Object
Dim Fol As Object
Dim Fil As Object
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Fol = Fso.GetFolder(strPath)
For Each Fil In Fol.Files
Debug.Print Fil.Path '打印路径及文件名
Debug.Print Fil.Name '打印文件名
Next
For Each Fol In Fol.subfolders
Debug.Print Fol.Path '打印子目录的路径及名称
Debug.Print Fol.Name '打印子目录的名称
SeachFile Fol
Next
End SubPrivate Sub Command1_Click()
SeachFile ("C:\Test\")
End Sub
如果要得出某文件夾下某類型的所有文件(如TXT文件)該如何做?
......
For Each Fil In Fol.Files
If CreateObject("Scripting.FileSystemObject").GetExtensionName(Fil.Name)="txt" Then Debug.Print Fil.Path '打印路径及文件名
Next
......
也謝謝樓主的貼子
这里加判断语句:
if right(fil.name,3)= "txt" then
Debug.Print Fil.Path '打印路径及文件名
Debug.Print Fil.Name '打印文件名
end if
Next
For Each Fil In Fol.Files
这里加判断语句:
if Fil.Type= "文本文档" then
Debug.Print Fil.Path '打印路径及文件名
Debug.Print Fil.Name '打印文件名
end if
Next
Option Explicit
Public Sub SeachFile(ByVal strPath As String) Dim Fso As Object
Dim Fol As Object
Dim Fil As Object
Dim strName As String
Dim i As String
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Fol = Fso.GetFolder(strPath)
' Fso.GetExtensionName ("C:\AUTOEXEC.BAT") For Each Fil In Fol.Files
Debug.Print Fil.Path
Debug.Print Fil.Name
Fso.getextensionname (Fil.Name)
' Debug.Print Fso.getextensionname(Fil.Name)
If Fso.getextensionname(Fil.Name) = "txt" Then---------------------此处改动
strName = Mid(Fil.Name, 1, InStr(1, Fil.Name, ".") - 1)
Debug.Print strName
End If-------------------------------------------------------------此处改动
Next
For Each Fol In Fol.subfolders
Debug.Print Fol.Path
Debug.Print Fol.Name
SeachFile Fol
Next
End SubPrivate Sub Command1_Click()
SeachFile ("C:\Test\")
End Sub