Function TotalNum(str)
dim n
n = 0
Dir = "template"
set fso = CreateObject("Scripting.FileSystemObject")
set Folder = fso.GetFolder(Dir)
For each oFile in Files
FileName = oFile.name
If InStr(FileName,str) <> 0 then
n = n + 1
End If
Next
set fso = nothing
TotalNum = n
End Function
使用InStr查询字符串在文件名中的开始位置,从头开始返回1,不存在返回0
同时可以对上述代码进行修改添加限制条件,比如限制后缀为 .mdb
Function TotalNum(str)
dim n
n = 0
Dir = "template"
set fso = CreateObject("Scripting.FileSystemObject")
set Folder = fso.GetFolder(Dir)
For each oFile in Files
FileName = oFile.name
If InStr(str,".mdb") <> 0 Then
If InStr(FileName,str) <> 0 Then
n = n + 1
End If
End If
Next
set fso = nothing
TotalNum = n
End Function