|
|
|
Click here to copy the following block | Private Sub Command1_Click() Dim col As Collection
Set col = GetAllFiles("c:\", "*.*", False, 30, 5) For Each f In col Debug.Print FileDateTime(f) & "=>" & f Next End Sub
Function GetAllFiles(ByVal path As String, Optional ByVal filespec As String = "*.*", _ Optional RecurseDirs As Boolean = False, Optional NewerThan As Integer = 0, Optional OlderThan As Integer = 0) As Collection Dim spec As Variant Dim file As Variant Dim subdir As Variant Dim subdirs As New Collection Dim specs() As String Dim bFlag As Boolean Dim dtFileModified As Date
Set GetAllFiles = New Collection
If Right$(path, 1) <> "\" Then path = path & "\"
specs() = Split(filespec, ";")
On Error Resume Next
For Each spec In specs file = Dir$(path & spec) Do While Len(file) file = path & file
If NewerThan > 0 Or OlderThan > 0 Then bFlag = True dtFileModified = FileDateTime(file) If (NewerThan > 0) Then If DateDiff("d", dtFileModified, Date) < NewerThan Then bFlag = True Else bFlag = False End If End If If (bFlag = True) And (OlderThan > 0) Then If DateDiff("d", dtFileModified, Date) > OlderThan Then bFlag = bFlag And True Else bFlag = False End If End If If bFlag = True Then GetAllFiles.Add file, file End If Else GetAllFiles.Add file, file End If
file = Dir$ Loop Next
If RecurseDirs Then file = Dir$(path & "*.*", vbDirectory) Do While Len(file) If file = "." Or file = ".." Then ElseIf (GetAttr(path & file) And vbDirectory) = 0 Then Else file = path & file subdirs.Add file, file End If file = Dir$ Loop
For Each subdir In subdirs For Each file In GetAllFiles(subdir, filespec, True) If NewerThan > 0 Or OlderThan > 0 Then bFlag = True dtFileModified = FileDateTime(file) If (NewerThan > 0) Then If DateDiff("d", dtFileModified, Date) < NewerThan Then bFlag = True Else bFlag = False End If End If If (bFlag = True) And (OlderThan > 0) Then If DateDiff("d", dtFileModified, Date) > OlderThan Then bFlag = bFlag And True Else bFlag = False End If End If If bFlag = True Then GetAllFiles.Add file, file End If Else GetAllFiles.Add file, file End If Next Next End If End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|