Identify the latest file file in FTP folder

Hi everyone.

I have connected to our FTP server and used the Enumerate Objects activity to get a list of files in the Remote Path. I want to identify the latest ZIP file and I will then use that name as part of the Remote Path in the Download Files activity to retrieve it.

What is the easiest way to identify the latest ZIP File? Should I interrogate the Output of the Enumerate Objects output via a For Each process?

Thanks

Craig…

Hi @craig.norton ,

Can you give a try,

your Enumerate Objects variable is sftpEnumFiles

Step1: Get .zip file modified time

modifiedArray = sftpEnumFiles.AsEnumerable().Where(Function(x) x.FullName.ToString.Contains(".zip")).ToList().select(Function(y) y.Modified.ToString).toarray()

Step2: Get latest updated date

latestUpdateDate = modifiedArray.AsEnumerable().OrderBy(Function(y) datetime.ParseExact(y.ToString,"MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture)).Reverse(0)

Step3: Latest updated file Name

latestUpdatedFileName = sftpEnumFiles.AsEnumerable().Where(Function(x) x.FullName.ToString.Contains(".zip")).ToList().AsEnumerable().Where(Function(y) y.Modified.ToString=latestUpdateDate).ToArray().Select(Function(y) y.FullName).Toarray(0)

You will get latest updated file

Thanks!

@craig.norton

You can try this

outenumftp.Where(function(x) x.FullName.ToLower.Contains(".zip")).OrderByDescending(function(x) x.Created)(0).FullName

This will give FullName of the Latest zip file…if you need whole object then just remove .FullName at the end and you would have the latest file object with you

This can be used in assign activity

Hope this helps

cheers

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.