How to copy/deleting the file? Please help!

  • Thread starter Thread starter Martin Ho
  • Start date Start date
M

Martin Ho

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
*-----------------------*
 
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
 
Hi Kerry,

Your code is fine, but bear this in mind: if you copy a file into a
subdirectory, fileinfo.creationtime is changed to the date and time of the
copy, even though a DOS listing indicates otherwise.

Bernie Yaeger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top