Getting latest file in a folder - Getfolderitem


Can anyone point me in the right direction i need to get the latest file from a folder. Not sure of the best way to accomplish this.



You want to look through all items in a single folder and find the one with the highest modification date?
Try this:

dim dir as FolderItem // set this to your directory to check dim highestDateValue as Double dim highestDateItem as FolderItem dim n as Integer = dir.Count-1 for idx as Integer = 1 to n dim f as FolderItem = dir.TrueItem(idx) if f = nil then continue // this file is not accessible, so let's skip it if dir.Directory then continue // check only files, not folders dim dateValue as Double = f.ModificationDate.TotalSeconds if dateValue > highestDateValue then // this item is newer than all the others we've looked at so far highestDateValue = dateValue highestDateItem = f end next // now highestDateItem is either nil (if the dir was empty) or contains // the latest file or folder