bbimis
asked on
need help finding the oldest directory that isn't empty using vb.net
can't seem to figure out how to get the oldest directory that isn't empty. i have tried the following code but end up getting the wrong directory
Private Function checkdiff()
Try
Dim folder As New DirectoryInfo("c:\program files")
Dim oldest As DirectoryInfo = Nothing
For Each dir As DirectoryInfo In folder.GetDirectories()
If oldest Is Nothing Then
oldest = dir
ElseIf dir.CreationTime < oldest.CreationTime Then
If dir.GetFiles.Length > 1 Then
oldest = dir
End If
End If
Next
Dim difference As Long
If oldest IsNot Nothing Then
difference = DateDiff(DateInterval.Day, Date.Now, oldest.LastWriteTime)
MsgBox("The difference in the date is: " & difference.ToString() & " Directory is : " & oldest.FullName)
Else
MsgBox("The directory does not exist")
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad I could help :)
ASKER