LB Booster
« Checking If A File Has Been Updated »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:31am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Checking If A File Has Been Updated  (Read 139 times)
Mystic
Junior Member
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 53
xx 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...
User IP Logged

- Rick
tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx 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.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
User IP Logged

Mystic
Junior Member
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 53
xx 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!!!
User IP Logged

- Rick
Mystic
Junior Member
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 53
xx 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!
User IP Logged

- Rick
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls