473,396 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Files & dates - help

Two questions:

1.)
I am copying a whole bunch of files from one directory, but I need to
do a if command to copy on those which date of creation is the same
as today's date. How do I do this comparision?

To give you some hint , this is how it could look but this of course
doesn't work, both variables return date with the time signature...I
need to compare only dates between date of creation and local date.

if System.IO.File.GetCreationTime(path to my file) = date.Now then
copy ....
end if
2.)
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
1 1353

Jan. 6, 2005

Instead of using Now (which includes the exact time) use Now.Date.

Dim f As New DirectoryInfo("PATH")
Dim fi As FileInfo
For Each fi In f.GetFiles
Dim d As Date
d = CType(File.GetCreationTime(fi.FullName), DateTime).Date
Dim t As New TimeSpan(28, 0, 0, 0) '
Timespan(days,hours,minutes,seconds)
If d.Date = Now.Date.Subtract(t) Then
fi.Delete()
End If
Next

This will convert the datetime object that is returned with
GetCreationTime to a date object. Datetime objects have a date property that
only returns the day in the form of Month/Day/Year. Then it compares the
file's date to Now.Date.Subtract(timespan) where timespan is a object created
earlier that specifies the number of days. Then it deletes it if it is 28
days old. If this message helped you, then please click on the "Yes" box
above this message. Thank you and I hope this helps!
Joseph MCAD
"Martin Ho" wrote:
Two questions:

1.)
I am copying a whole bunch of files from one directory, but I need to
do a if command to copy on those which date of creation is the same
as today's date. How do I do this comparision?

To give you some hint , this is how it could look but this of course
doesn't work, both variables return date with the time signature...I
need to compare only dates between date of creation and local date.

if System.IO.File.GetCreationTime(path to my file) = date.Now then
copy ....
end if
2.)
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

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

Similar topics

4
by: J P Singh | last post by:
Hi All I am trying to query a database with a combination of surname and date of birth but it is giving me wrong results in certain conditions. It is the mm/dd/yyyy and dd/mm/yyyy stuff that...
5
by: Raj | last post by:
Hi all, Can anyone help me with a script which would delete files or move them to a different folder at some scheduled time..! Please.....!!! Thanks in advance...
4
by: kinne | last post by:
The following code is supposed to reverse the date in "yyyy-mm-dd" format, but it produces different results in Firefox 1.0 and in Internet Explorer 6SP1. In Firefox, the result is correct...
9
by: Ray | last post by:
I need to convert the normal calendar to show the week no., the period no. and the financial year. The financial year format is as follows:- Date start: 2 May, 2005 7 days a week, 4 weeks a...
0
by: Vijay | last post by:
Prep Courses for International Certifications, CSTE & CSQA & ISEB & ISTQB &Business Analyst & SOA Certifications in HYDERABAD. After receiving overwhelming response to our last 50+ batches, ...
2
by: Nathan Sokalski | last post by:
I am moving my website from my machine to my webhost, and need some help with what extra files I need to include due to the fact that I used AJAX in my site. Everything on the site is obviously...
12
by: jonathan184 | last post by:
Hi the purpose of the script I am trying to do is to access a dir and run the ls -l command which will show the files and the modified date, no w the script is to check two files in that dir , if the...
9
by: LucasLondon | last post by:
Hi, Sorry, this is a bit of a lengthy one but I guess too much information is better than less! I have an excel worksheet that I update regulary with latest values from downloaded CSV files....
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.