Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Xbase Fox > Re: Latest File...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 5 Topic 769 of 861
Post > Topic >>

Re: Latest File Modification Date

by Gene Wirchenko <genew@[EMAIL PROTECTED] > May 17, 2007 at 05:48 PM

Gene Wirchenko <genew@[EMAIL PROTECTED]
> wrote:

>     I am updating my app loader program.  One of the things that I
>need to determine is the executable with the latest date (in the
>directory entry).  This is surprisingly awkward, because adir()
>returns date and time separately, and asort() sorts one column.
>Perhaps, I am missing a more suitable function.
>
>     Approach 1:
>          adir() to get the candidate filenames
>          asort() by date descending
>          find last element in array with latest date
>          asort() by time descending elements with latest date
>          return first filename in array
>
>     Approach 2:
>          adir() to get the candidate filenames
>          create cursor
>          append cursor from array
>          select max(dtos(dirdate)+dirtime) as maxwhen from cursor
>          select * from cursor where dtos(dirdate)+dirtime=maxwhen
>           into cursor2
>          return first filename in cursor2 (Ideally, there is only 1.)
>
>     Ha!  And I thought that the SQL approach would be shorter.

     <pause>

     Hmm, no answers?  Well, I ended up with:

***** Start of included Code *****
* getlatestfilename
* Get Latest Filename
* Last Modification: 2007-05-17
*
* Usually returns the filename of the latest modified file matching
* cFileSkeleton and cAttribute.  In the case of a timestamp tie, one
of the
* filenames will be returned, but which one is indeterminate.  Tie or
not,
* the filename is formatted as adir() does it.
* If no files match, returns "".
* If an error occurs, returns "".

procedure getlatestfilename
lparameters;
 cFileSkeleton,; && =C: adir()'s optional parameter 2
 cAttribute,;    && =C: adir()'s optional parameter 3
 nFlag           && =N: adir()'s optional parameter 4
* Trailing parameters may be omitted as with adir().

   local fileinfo(1), cfiles

   do case
   case pcount()=0
      cfiles=adir(fileinfo)
   case pcount()=1
      cfiles=adir(fileinfo,cFileSkeleton)
   case pcount()=2
      cfiles=adir(fileinfo,cFileSkeleton,cAttribute)
   case pcount()=3
      cfiles=adir(fileinfo,cFileSkeleton,cAttribute,nFlag)
   otherwise
      return ""
      endcase

   if cfiles=0
      return ""
      endif

   local fsort

   fsort=asort(fileinfo,3,-1,1)
   if fsort=-1
      return ""
      endif

   local clast, looping
   clast=1
   looping=.t.
   do while clast<cfiles and looping
      clast=clast+1
      looping=fileinfo(clast,3)=fileinfo(1,3)
      enddo
   clast=clast-1
   dimension fileinfo(clast,5)

   fsort=asort(fileinfo,4,-1,1)
   if fsort=-1
      return ""
      endif

   return fileinfo(1,1)

   endproc
***** End of included Code *****

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
     I have preferences.
     You have biases.
     He/She has prejudices.
 




 5 Posts in Topic:
Latest File Modification Date
Gene Wirchenko <genew@  2007-05-17 13:21:06 
Re: Latest File Modification Date
Gene Wirchenko <genew@  2007-05-17 17:48:15 
Re: Latest File Modification Date
Man-wai Chang <toylet.  2007-05-18 10:09:20 
Re: Latest File Modification Date
"Stefan Wuebbe"  2007-05-18 08:41:55 
Re: Latest File Modification Date
Bernhard Sander <fuchs  2007-05-18 11:23:11 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 13:51:49 CST 2008.