怎样取得各级子目录下的文件名(包含全路径)。

kuailexq2000 2010-09-15 09:17:27
要做一个替换某路径下所有文件中字符串的工具
...全文
114 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dision LI 2010-09-15
  • 打赏
  • 举报
回复
Tiger_Zhao 2010-09-15
  • 打赏
  • 举报
回复
Function SearchFiles(ByVal BasePath As String, Optional ByVal searchPattern As String = "*.*") As Collection
Dim colPathStack As Collection, colFiles As Collection
Dim sPath As String, sFound As String
Set colFiles = New Collection
Set colPathStack = New Collection
colPathStack.Add BasePath & IIf(Right$(BasePath, 1) <> "\", "\", vbNullString)
While colPathStack.Count <> 0
sPath = colPathStack(1)
colPathStack.Remove 1

sFound = Dir(sPath & "*.*", vbDirectory + vbHidden)
While LenB(sFound)
If (sFound <> ".") And (sFound <> "..") Then
If (GetAttr(sPath & sFound) And vbDirectory) <> 0 Then
colPathStack.Add sPath & sFound & "\"
End If
End If
sFound = Dir()
Wend

sFound = Dir(sPath & searchPattern, vbHidden)
While LenB(sFound)
colFiles.Add sPath & sFound
Debug.Print sPath & sFound

sFound = Dir()
Wend
Wend

Set SearchFiles = colFiles
End Function

7,766

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧