Martin,
This code displays all the files in a folder that have a creation date equal
to today's date:
Dim di As New DirectoryInfo("c:\test")
Dim fi As FileInfo
For Each fi In di.GetFiles
If fi.CreationTime.Date = DateTime.Now.Date Then
MsgBox(fi.FullName & " " & fi.CreationTime.Date)
End If
Next
This code displays all the files in a folder that were created 28 or more
days ago:
Dim di As New DirectoryInfo("c:\test")
Dim fi As FileInfo
For Each fi In di.GetFiles
If DateDiff(DateInterval.Day, fi.CreationTime, DateTime.Now) >=
28 Then
MsgBox(fi.FullName & " " & fi.CreationTime)
End If
Next
Be sure that CreationTime is the file property you want to check, and not
something else like LastWriteTime.
Kerry Moorman
"Martin Ho" wrote:
Can someone help me with this please? I wasn't very clear in my old
post.
I have a program to copy files from one location to another, now I
want to copy only those files which were created on certain date. How
do I compare the file (date created) to system date?
Something like this doesn't work:
if System.IO.File.GetCreationTime(path to my file) = date.Now then
copy ....
end if
Also, when we are already talking about date comparision, any idea how
I would go about deleting all files that are 4 weeks (28 days) older
than today's date?
Thanks a lot for all your help and time.
Martin
*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*