Wine Too
Wine Too

Reputation: 4655

Howto GetFiles with desired extension between dates sorted descending by filename

I am getting files of desired extension in directory with this:

Dim files As FileInfo()
files = New DirectoryInfo(myPath).GetFiles("*." & dExt).Where(Function(x) _
x.CreationTime >= (st_date) AndAlso x.CreationTime <= (end_date)).ToArray()

This work's ok.
But I don't know to incorporate 'OrderByDescending' in this expression.

Please if somebody can show me how to add 'OrderByDescending' clause in showed code.
Second, I would like to know if GetFiles can be defined for two expressions.
For example to get files of extensions ".7z" and ".arj" at once in defined path.

Upvotes: 1

Views: 1176

Answers (1)

Wine Too
Wine Too

Reputation: 4655

I find a solution for all which may be interested...

    Dim files As FileInfo()
    files = New DirectoryInfo(myPath).GetFiles("*." & dExt, SearchOption.TopDirectoryOnly) _
           .OrderByDescending(Function(x) x.FullName) _
           .Where(Function(x) x.CreationTime >= (st_date) AndAlso x.CreationTime <= (end_date)) _
           .ToArray()

Also, there are solutions for browsing multiple extensions but no one so elegant as I wish.

Upvotes: 1

Related Questions