Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Update Local file based on time modified comparison
#1
Hi All,
I have a local db file that I want to check against a network copy for any updates. I wrote this script (see below) to compare the time modified and used the DateTime function to help with numerical comparison. I am assuming that the larger number represents the more recent file. Will that always be true?
I could do more testing but thought I would post the code here and see if anyone knows more elegant way.

Thanks!!! S

Function UpdateDb
Code:
Copy      Help
str- NetworkDbFile="\\NetworkLocation\AdminDB.db3"
str- LocalDbFile="$common documents$\AdminDB.db3"

if(!dir(LocalDbFile));;if local copy does not exist
,out "Copying AdminDb from network....."
,cop- NetworkDbFile LocalDbFile; err ErrMsg(1)
,out "Copying AdminDb.....done."
,
Dir d1
if d1.dir(NetworkDbFile 0) ;;if exists
,DATE dNetworkTimeMod=d1.TimeModified2
,
Dir d2
if d2.dir(LocalDbFile 0) ;;if exists
,DATE dLocalTimeMod=d2.TimeModified2


out NetworkTimeMod
out LocalTimeMod

DateTime dtNetworkTimeMod.FromDATE(dNetworkTimeMod)
DateTime dtLocalTimeMod.FromDATE(dLocalTimeMod)

out dtNetworkTimeMod
out dtLocalTimeMod
;
if dtNetworkTimeMod > dtLocalTimeMod
,cop- NetworkDbFile LocalDbFile; err ErrMsg(1)
,
#2
This is correct.

------

shorter

Function UpdateDb
Code:
Copy      Help
str- NetworkDbFile="\\NetworkLocation\AdminDB.db3"
str- LocalDbFile="$common documents$\AdminDB.db3"

;if(!dir(LocalDbFile));;if local copy does not exist
,;out "Copying AdminDb from network....."
,;cop- NetworkDbFile LocalDbFile; err ErrMsg(1)
,;out "Copying AdminDb.....done."

Dir d1
if d1.dir(NetworkDbFile 0) ;;if exists
,long dtNetworkTimeMod=d1.TimeModified(0 0 0 1)
,
Dir d2
if d2.dir(LocalDbFile 0) ;;if exists
,long dtLocalTimeMod=d2.TimeModified(0 0 0 1)

out dtNetworkTimeMod
out dtLocalTimeMod
;
if dtNetworkTimeMod > dtLocalTimeMod
,cop- NetworkDbFile LocalDbFile; err ErrMsg(1)
,

TimeModified returns time in same format as in DateTime variables.
#3
Why not just have QM monitor the file with a trigger and then have it copy on change? This way you would always get the fresh copy immediately on change. This is unless you are not always on the network (e.g. Laptop)


Perhaps just test for any change for the server copy use the registry to store values (in words, I'm on a computer without QM) :
rdate = registry date modified from last copy
ndate = date modified of network database
If rdate is empty or !rdate=ndate
,then copy network database to local machine
,write ndate to the registry
#4
Thanks All!
Stuart


Forum Jump:


Users browsing this thread: 1 Guest(s)