[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB.Net - shortcut to obtaining most recent file

Posted on 2016-07-18
3
Medium Priority
?
59 Views
Last Modified: 2016-07-18
Trying to find the most recent file with the following code:

 Dim FileList = New DirectoryInfo(SummaryDir).GetFiles(Fin + "*.xls").OrderByDescending(Function(x) x.CreationTime)
        For Each f As FileInfo In FileList
            lastfile = f.Name
            Exit For
        Next

Is there a way to avoid the for/next to obtain the last filename?
0
Comment
Question by:Member_2_7964482
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 41717080
sure. you can use FirstOrDefault like this:

MessageBox.Show(New DirectoryInfo("C:\temp").GetFiles("*.tmp").OrderByDescending(Function(x) x.CreationTime).FirstOrDefault().Name)

Open in new window

0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 41717083
HI,

maybe

        Dim fi As New New DirectoryInfo(SummaryDir)
        Dim files = fi.GetFiles(Fin + "*.xls").ToList
        Dim last = (From file In files Select file Order By file.CreationTime Descending).FirstOrDefault

Open in new window

Regards
0
 

Author Closing Comment

by:Member_2_7964482
ID: 41717418
Perfect solution.  Thank you
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question