Archived Forum Post

Index of archived forum posts


Get the latest file .need to compare the time

Mar 10 '16 at 17:35

I have list of files placed at SFTP server. I need my application to get the latest file placed. 2 files will be placed daily 3/8/2016 11:00PM 3/8/2016 2:00PM 3/7/2016 11:00PM 3/7/2016 2:00PM 3/6/2016 11:00PM 3/6/2016 2:00PM I need to sort and get the first one .Please help!!!


If you need to get only the latest file -- you don't need to sort. You simply need to make as single pass over the files in the SFtpDir object and keep the most recent one. In pseudo-code:

mostRecentFile = sftpDir.GetFileObject(0)
numFiles = sftpDir.NumFilesAndDirs
for i = 1 to numFiles-1
   f = sftpDir.GetFileObject(i)
   if f is more recent than mostRecentFile then  mostRecentFile = f

Sorting is more work than you actually need to do...