LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing file dates, ( " *.txt " files) with current system date

Hi there,

Here's my problem:
I'm loading a text file with a set of results from a test. Every 7 days I want a new file created & the old one save with the current date as part of the name of the file.

How do I compare the date of the text file with the current systems date?
I use the functions "SetFileDate(..)" & "GetFileDate(..)" to know when the file was created, but is there an easy way to find out if the file is older than 7 days?

Hope someone can help?

Kevin
0 Kudos
Message 1 of 2
(3,004 Views)
This sample code calculates date difference (in days) between today and a file date.
You can use it as a trace for your job.
It's based on mktime () function that returns the number of secs since January 1, 1900, on which you can calculate knowing that a day is 86400 secs.

#include
#include
static struct tm *zz;
static int err, mm, dd, yy;
static unsigned long ll;
static unsigned long fdate;

ll = time (NULL); // Today

err = GetFileDate ("yourfile.txt", &mm, &dd, &yy);
if (err) {
MessagePopup ("Error", Error in GetFileDate");
}
else {
zz = now; // Inizialize structure
zz->tm_year = yy - 1900;
zz->tm_mon = mm;
zz->tm_mday = dd;
fdate = mktime (zz);

printf ("File was created %.0f days ago.\n", (double)(ll - fdate) / 86400.0);
}


A little tricky and perhaps not 'politically correct', but it works.
Hope this helps.
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(3,004 Views)