473,508 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to copy/deleting the file? Please help!

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
3 1555
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
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
Kerry Moorman,
thanks so much. You just made my day.
Thanks a lot.
Martin

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1633
by: Petter L | last post by:
I getting the following message when using Filecopy command An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module. Additional information: Object...
4
2239
by: Alfonzo Morra | last post by:
I've the ff code in cp assignmenent cstor: PB& PB::operator=( const PB& b) { if ( this != &b ) { PB *pb = new PB( b ) ; this = pb ; // <- Compiler barfs here } return *this ; }
1
3103
by: dixie | last post by:
I am doing a job where I need to copy a letter header into each of about 100 letters which are mail merge template documents for about 20 different customers - all up about 2000 copy and pastes...
2
2117
by: melanieab | last post by:
Hi, I'm deleting nodes in my xml file, and it does seem to work, but then when I later reload the file and make an xmlNodeList, the nodelist count still includes the deleted nodes yet the file...
2
1779
by: Harry Barker | last post by:
Hi Group I Have to complete a small project and i need you guys help in doing it. I have to create a Tool that will automatically delete a file from the Harddrive and also deleting a SubKey from...
19
4167
by: Angus | last post by:
I have a socket class CTestClientSocket which I am using to simulate load testing. I create multiple instances of the client like this: for (int i = 0; i < 5; i++) { CTestClientSocket* pTemp...
4
1460
by: MiziaQ | last post by:
Hey, I'm using the following code to write entries to a data file and then read them in an msflexgrid. I now would like to add code under a delete button to use the table(grid) to delete rows from...
13
2584
by: jim | last post by:
Is there a way (using VB.Net or C#) to copy open or locked files? Thanks! jim
5
1144
by: =?Utf-8?B?YmVlamF5?= | last post by:
Whilst attempting to delete files in a folder all I get is a double up of the original file without any deletion; I now have at least 9 copies of the original file!!! Please can someone help? --...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.