Author |
Topic: Checking If A File Has Been Updated (Read 140 times) |
|
Mystic
Junior Member
member is offline
Gender:
Posts: 53
|
|
Checking If A File Has Been Updated
« Thread started on: Nov 22nd, 2017, 10:15pm » |
|
One of my programs has a data file that it loads when it first runs.
Instead of loading this data file at every pass, it just loads at the start.
If I update the data file I don't want to have to restart the program, so at the moment I just check a separate file with a single "1" or "0" in it to tell the program that a new data file is available.
A little cludgy, so I'd like to remedy this.
I would like to just look at the data file information (i.e. Date & Time) and if it's different than the previous version, reload the new data file.
Make sense?
So the question is, how would I just check if the data file is different than the previous one without actually opening the entire file?
As the program makes it to the top of the pass, it looks at the data file and says, "Oh look, an updated file, I need to load that one."
Thanks in advance...
|
|
Logged
|
- Rick
|
|
|
tsh73
Full Member
member is offline
Gender:
Posts: 210
|
|
Re: Checking If A File Has Been Updated
« Reply #1 on: Nov 23rd, 2017, 06:01am » |
|
You get date and time from FILES command Code:
fileName$="data.txt"
'create data file
open fileName$ for output as #1
print #1, "data goes here"
close #1
print "Time stamp for a file ";fileName$
print getFileStamp$(fileName$)
function getFileStamp$(fileName$)
dim info$(1,1)
files DefaultDir$, fileName$, info$()
if info$(0, 0) = "0" then
getFileStamp$ = "File not found"
else
getFileStamp$ = info$(1, 2)
end if
end function
But you still need a file to store last date/time - to check if date/time had changed.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Checking If A File Has Been Updated
« Reply #2 on: Nov 23rd, 2017, 08:32am » |
|
on Nov 23rd, 2017, 06:01am, tsh73 wrote:You get date and time from FILES command |
|
Just to add that if you need to know which is the newer of two files (rather than simply whether the date/time has changed) this is difficult in LB 4, because the format in which it is returned depends on your locale settings. So for example in the US the date is returned as MDY whereas in the UK it is returned as DMY. There are other regional differences that complicate making a comparison.
In LBB v3.08 I introduced an extension to simplify this: the FILES array has an additional column (4) containing the date/time in a fixed, sortable, format (the date is YMD). So if you don't need your program to be compatible with LB 4, you can use column 4 rather than column 2.
Incidentally the documentation of the FILES statement in the Liberty BASIC help file fails to mention that column 3 contains the file's attributes (read-only, hidden, system, archive).
Richard.
|
|
Logged
|
|
|
|
Mystic
Junior Member
member is offline
Gender:
Posts: 53
|
|
Re: Checking If A File Has Been Updated
« Reply #3 on: Nov 24th, 2017, 4:00pm » |
|
Great info!
I appreciate the assist. The day after Turkey Day is slow at work so it gives me some much needed programming time to tweak my existing code.
Thanks again!!!
|
|
Logged
|
- Rick
|
|
|
Mystic
Junior Member
member is offline
Gender:
Posts: 53
|
|
Re: Checking If A File Has Been Updated
« Reply #4 on: Dec 7th, 2017, 5:37pm » |
|
Just to close the loop on this, the provided information helped me get the exact result I needed.
Thank you again for the information!
|
|
Logged
|
- Rick
|
|
|
|