|
2#
楼主 |
发表于 2012-3-25 21:43:08
|
只看该作者
没人顶吗?
顶一下。顺便再问两个问题。
问题1:还是根据前面的想法,我利用FileSystemObject做了一个功能,但似乎代码有问题,无法运行,到底哪里出了问题?请各位指正。
问题2:想FUNCTION一类的功能究竟有什么办法可以进行测试(正确与否,是否有语法错误什么)吗?
问题1:
Option Compare Database
Option Base 1
'strFile()为文件名的数组
Dim strFile() As String
'iFile为文件数量
Dim iFile As Integer
Function FilesSearch(FolderPath As String, Key As String) As bolean
Dim fso As FileSystemObject
Dim aFolder As folder
Set fso = New FileSystemObject
'如果指定路径文件夹不存在,FilesSearch=False
If fso.FolderExists(FolderPath) = False Then
strFile() = ""
FilesSearch = False
Exit Function
Else
Set aFolder = fso.GetFolder(FolderPath)
'如果指定文件类型不存在,FilesSearch=False
If fso.FileExists(FolderPath & "\" & "*." & Key) = False Then
strFile() = ""
FilesSearch = False
Exit Function
Else
'如指定文件类型存在,FilesSearch=True,iFile累加,文件名加入数组
For Each File In aFolder.Files
If File.Name Like FolderPath & "\" & "*." & Key Then
ReDim Preserve strFile(iFile)
strFile(iFile) = aFolder.Files(iFile).Name
iFile = iFile + 1
End If
Next File
FilesSearch = True
End If
End If
End Function
|
|