473,807 Members | 2,857 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 1590
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.Da te Then
MsgBox(fi.FullN ame & " " & 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(DateIn terval.Day, fi.CreationTime , DateTime.Now) >=
28 Then
MsgBox(fi.FullN ame & " " & 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.creati ontime is changed to the date and time of the
copy, even though a DOS listing indicates otherwise.

Bernie Yaeger

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> wrote in message
news:67******** *************** ***********@mic rosoft.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.Da te Then
MsgBox(fi.FullN ame & " " & 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(DateIn terval.Day, fi.CreationTime , DateTime.Now) >=
28 Then
MsgBox(fi.FullN ame & " " & 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
1644
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 reference not set to an instance of an object. If I break then I get "There is no source code avaliable for the current
4
2252
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
3118
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 requiring opening each document and deleting the current header and pasting the new one. I have tried to use IncludeText to do this and having the header in a file, but it appears that the client must open each letter and refresh the link before...
2
2137
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 shows no sign of them. Here is what I have: Example of my xml: <Catalog> <File ID = "1"> <Customer>Me</Customer>
2
1799
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 the registry. Before doing the same, the tool have to check the version of Windows. Ex: For Example if you guys could suggest me a coding where i can delete
19
4213
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 = new CTestClientSocket(this, ip, port); pTemp->Connect(); m_collClients.push_back(pTemp);
4
1480
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 the file. How can I do that. I have some code for deleting a row from the table, but it's only deleting the row from the table, and not the entry itself. Please help! Is there a relatively easy way to do this ? Private Sub cmdAddDelivery_Click() ...
13
2622
by: jim | last post by:
Is there a way (using VB.Net or C#) to copy open or locked files? Thanks! jim
5
1165
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? -- beejay
0
9720
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9599
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10626
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3854
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.