Some lesson: which file is more updated than the other?
Posted: 17 Jul 2015 5:41
I needed to implement a predicate that tells me if one file is more updated than another. Here is how I went about it and the lesson I learnt.
Code: Select all
/* This predicated succeeds if the first file is more updated than the second one*/ predicates is_more_updated:(string Filename1, string Filename2) determ. clauses is_more_updated(Filename1, Filename2):- /* Get the GMT times when the files were last changed*/ file::getFileProperties(Filename1,_,_,_,_,Gmt1), file::getFileProperties(Filename2,_,_,_,_,Gmt2), /* Now I need to find out which date/time is more recent and I tried the following:- Gmt1>Gmt2,!, %This compiled but gave me wrong results; then I tried:- compare(Gmt1, Gmt2) = ::greater,!, %This too compiled but gave me wrong results. Finally I tried (which worked):-*/ Time1=time::newFromGMT(Gmt1), Time2=time::newFromGMT(Gmt2), Time1:compare(Time2)=::greater.