Hi,
I'm working on searching error files based on time.
I have 2 folders which have permanent and temporary error files in it, and the only difference between permanent and temporary error files is creation time. I’m searching for error files in these 2 folders and my search should only return permanent error files not the temporary ones. Here is the code snippet.

Dim searchDir2 As New IO.DirectoryInfo("C:\ERROR_FOLDER")
        Dim fileArray2 As IO.FileInfo() = searchDir2.GetFiles("*.error")



        Dim fileName2 As IO.FileInfo

        For Each fileName2 In fileArray2
            If fileName2.CreationTime.Date <= curTime Then
            temp = fileName2.Name
            temp3 = "C:\ _ERRORS" & temp

I’m working on the if statement but not able to get it working. i want the error files whose creation time is less than 1 hour of the current time. Any help is appreciated.

Thanks

I think you have to work with the hours part of the date. Something like
if fileName2.CreationTime.Hour <= Now.TimeofDay.Hours then
.....
...
end if
Try that!

I think you have to work with the hours part of the date. Something like
if fileName2.CreationTime.Hour <= Now.TimeofDay.Hours then
.....
...
end if
Try that!

This solved my problem:
If DateDiff(DateInterval.Hour, fileName2.CreationTime, now) > 1 Then

Thanks for your help again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.