WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: MW4 on July 28, 2016, 12:56:56 PM

Title: Quick oldest item question
Post by: MW4 on July 28, 2016, 12:56:56 PM
I an using this  function and would like to just get the oldest file (singular file)

#DefineFunction FileItemizeByDate(filemasks,option)
   ; Listing files by date
   ; Sort files by Y:M:D:H:M:S (date)
   ; Option @Ascending lists oldest to newest,@Descending lists newest to oldest
   arrFiles=FileInfoToArray(filemasks) ;retrieves unsorted list
   ; Remove header column
   ArrayRemove( arrFiles, 0, 1)
   ;Sort the array on the modified column
   ArraySort( arrFiles, option, 2 )
   ;Create a tabdelimited list of file names
   filelist = ''
   For xx = 0 To 0
      dafile =  arrFiles[xx,0]
      If filelist == "" Then filelist = dafile
      Else filelist = filelist:@TAB:dafile
   Next
   Return filelist
#EndFunction


DirChange('\\fleetdc01\Fleet\Miscellaneous\test\')
filelist = FileItemizeByDate('*.pdf',@ASCENDING) ; oldest to newest
result = AskItemlist("Files: oldest to newest", filelist, @TAB, @UNSORTED, @SINGLE )


Something like Message("oldest", (first item in filelist) )

Ideas?
Title: Re: Quick oldest item question
Post by: td on July 28, 2016, 01:44:19 PM
Assuming you sort in ascending order, just return the file in the first row of the array.
Title: Re: Quick oldest item question
Post by: MW4 on July 28, 2016, 02:09:21 PM
That worked...thanks!!