How to convert IEnumerable<FtpObjectInfo> into a datatable

Hi, after using Enumerate objects from set of FTP activities… we get result in IEnumerable a kind of list carrying the details around each file/directory within that FTP location.

Each item within this IEnumerable there are file properties stored… like Created, FullName, Name, Type etc…each item is of type FtpObjectInfo

image

I wanted to convert this whole list into a datatable, with the file properties as columns and values as rows… Can someone please help on how to do this?

Ultimately I wanted to filter this big list of FtpObjectInfo based on a patter on Name, I was thinking I will do this filtering when the list gets converted into a datatable

If someone can help me filter this IEnumerable.Name with Regex without even converting into a datatable that is even better solution from the performance

Once I find the list of files that match my pattern (on its name) I will move those files form FTP to local computer. This is my usecase

Thanks,
Kiran

@kduvvuri
Build datatable with headers as given in one IEnum <>
Iterate through each assign the value and use add data row

@kduvvuri

Give a try on filtering it with LINQ
sftpFiles.Where(Function (x) x.Name.Contains(YourSearchTerm)).toList

About LINQ have a look here:

Also have a look on following activtiy and its output property Files returning a datatable

I am trying to use the LINQ query … I know I am doing something incorrect, as its not yielding the result

sftpFiles.Where(Function(m) system.Text.RegularExpressions.Regex.Match(m.Name,"^kiran+[.a-zA-Z0-9_-]+[0-9]+.(xlsx|txt|xls)$"))

so I hard coded the regex to see if its working, but not

sftpFiles.Where(Function(m) system.Text.RegularExpressions.Regex.Match(m.Name,“dvijay”))

however below expression works … but see here its not iterating within the iEnum

System.Text.RegularExpressions.Regex.Match(sftpFiles(0).Name,“dvijay”)

since above expression is working, I implemented the actual regex and this does not work :frowning:

System.Text.RegularExpressions.Regex.Match(sftpFiles(15).Name,"^kiran+[.a-zA-Z0-9_-]+[0-9]+.(xlsx|txt|xls)$")


Never mind below expression worked

sftpFiles.Where(Function(m) System.Text.RegularExpressions.Regex.IsMatch(m.Name,"^kiran+[\s.a-zA-Z0-9_-]+[0-9]+.(xlsx|txt|xls)$"))

Peferct it is running

As mentioned in the tutorial the first statement with Regex.Match was not returning a boolean to the lambda. The later used one with RegEx.IsMatch had an boolean outcome. So it was working.

yes it is … thank you

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