By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,369 Members | 1,131 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,369 IT Pros & Developers. It's quick & easy.

How to copy/deleting the file? Please help!

P: n/a
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
*-----------------------*
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
*-----------------------*

Nov 21 '05 #2

P: n/a
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

"Kerry Moorman" <Ke**********@discussions.microsoft.com> wrote in message
news:67**********************************@microsof t.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

"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
*-----------------------*

Nov 21 '05 #3

P: n/a
Kerry Moorman,
thanks so much. You just made my day.
Thanks a lot.
Martin

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.