Hey guys,
I have a function that counts files from disk recursively.
The files searched for have a date in the name, and the function will allready count files from today.
This works well but now i have to count files that have a timestamp in the name between 0800 - 1800 hrs.
This is an example of the name of the file im searching for :
22-01-2016 1533 Test.pdf
As you can see the "time" is 1533 hrs and this file needs to be counted. where as a time lets say 0745 does not.
I tried putting a between statement inside it, but it doesnt work.
This is the function :
Code:
Dim colFiles As New Collection
RecursiveDir colFiles, "I:\MyDirecory", "" & Format(Date, "dd/mm/yyyy") & "*.pdf", True
Dim vFile As Variant
For Each vFile In colFiles
ctrlTest = colFiles.Count
Next vFile
Function :
Code:
Public Function RecursiveDir(colFiles As Collection, _
strFolder As String, _
strFileSpec As String, _
bIncludeSubfolders As Boolean)
Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant
'Add files in strFolder matching strFileSpec to colFiles
strFolder = TrailingSlash(strFolder)
strTemp = Dir(strFolder & strFileSpec)
Do While strTemp <> vbNullString
colFiles.Add strFolder & strTemp
strTemp = Dir
Loop
If bIncludeSubfolders Then
'Fill colFolders with list of subdirectories of strFolder
strTemp = Dir(strFolder, vbDirectory)
Do While strTemp <> vbNullString
If (strTemp <> ".") And (strTemp <> "..") Then
If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0 Then
colFolders.Add strTemp
End If
End If
strTemp = Dir
Loop
'Call RecursiveDir for each subfolder in colFolders
For Each vFolderName In colFolders
Call RecursiveDir(colFiles, strFolder & vFolderName, strFileSpec, True)
Next vFolderName
End If
End Function
Public Function TrailingSlash(strFolder As String) As String
If Len(strFolder) > 0 Then
If Right(strFolder, 1) = "\" Then
TrailingSlash = strFolder
Else
TrailingSlash = strFolder & "\"
End If
End If
End Function
Any suggestions ?