Office07,2010中的Application.Filesearch替代方法-杜小杰
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-模块/函数/VBA


Office07,2010中的Application.Filesearch替代方法

发表时间:2012/5/29 16:51:44 评论(1) 浏览(17859)  评论 | 加入收藏 | 复制
   
摘 要:第一个类,命名为FileSearh: 
正 文:

Dim pLookIn As String Dim pSearchSubFolders As Boolean Dim pFileName As String

Public FoundFiles As New Collection

Public Property Get LookIn() As String

LookIn = pLookIn

End Property

Public Property Let LookIn(value As String)

pLookIn = value

End Property

Public Property Get SearchSubFolders() As Boolean

LookIn = pSearchSubFolders

End Property

Public Property Let SearchSubFolders(value As Boolean)

pSearchSubFolders = value

End Property

Public Property Get fileName() As String

fileName = pFileName

End Property

Public Property Let fileName(value As String)

pFileName = value

End Property

Public Function Execute() As Long

Dim ex As Long

Dim sLookIn As String

Dim sDirName As String

Dim sSubDir As String

Dim sFileName As String

Dim ff As FilesFound

Set ff = New FilesFound

sLookIn = LookIn

sDirName = Dir(sLookIn, vbDirectory)

sFileName = Dir(sLookIn & "\", vbNormal)

Do Until Len(sFileName) = 0

If sFileName Like fileName Then

ff.AddFile sLookIn, sFileName

FoundFiles.Add (ff.FoundFileFullName)

End If

sFileName = Dir

Loop

If SearchSubFolders Then

Do Until Len(sDirName) = 0

If GetAttr(sLookIn & sDirName) = vbDirectory Then

sSubDir = sDirName

Do Until Len(sFileName) = 0

If GetAttr(sDirName) = vbNormal Then

sFileName = sDirName

ff.AddFile sDirName, sFileName

FoundFiles.Add (ff)

End If

Loop

End If

sDirName = Dir

Loop

End If

Execute = FoundFiles.Count

End Function


第二个类,命名为FilesFound :


Public FoundFileFullName As String

Public Function AddFile(path As String, fileName As String)

FoundFileFullName = path & "\" & fileName

End Function


使用:

 Dim sFile as String

Dim fs As New FileSearh

 With fs

.LookIn = sPath

.SearchSubFolders = True

.fileName = "*"

If .Execute > 0 Then

For i = 1 To .FoundFiles.Count

sFile = .FoundFiles(i)

 ' Your code here

 Next

End If

End With


这种办法虽然相当原来的功能有一些少,但是可以一定程度上减少代码移植的成本。


Access软件网交流QQ群(群号:198465573)
 
 相关文章
【通用模块源码】通用文件搜索类模块(FileSearch替代方法)  【红尘如烟  2010/9/7】
Access2013与Access2010的区别  【周芳  2013/3/19】
access 2010 vba 中的me是什么意思?  【sexbee  2013/3/31】
彻底隐藏Access2010功能区示例,access2010如何隐...  【麥田  2013/4/4】
Access2010数据库技术及应用(PDF文档/电子书)  【宏鹏(分享)  2013/4/10】
常见问答
技术分类
相关资源
文章搜索
关于作者

杜小杰

文章分类

文章存档

友情链接