Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting newest Excel filename from folder
Message
 
To
25/01/2007 16:05:30
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB.NET 1.1
Miscellaneous
Thread ID:
01187847
Message ID:
01189524
Views:
10
It is good! Thanks for sharing. I still was under impression that there is nothing better than what was discussed in Thread #1020162.



>
>        Private Shared Function GetLatestExcelFileInDir(ByVal dir As String) As String
>
>            Dim dirInfo As System.IO.DirectoryInfo
>            Dim files As System.IO.FileInfo()
>            Dim datesAndNames As String()
>            Dim dt As DateTime
>
>            Try
>                'Get directory info of dir
>                dirInfo = New System.IO.DirectoryInfo(dir)
>                'Get excel files in dir
>                files = dirInfo.GetFiles("*.xls")
>                'Create string array to hold file names and dates
>                datesAndNames = New String(files.Length - 1) {}
>
>                'Enumerate through files
>                For i As Integer = 0 To files.Length - 1
>                    'Get creation date of file
>                    dt = files(i).CreationTime
>                    'Store creation date and file name in one text field
>                    datesAndNames(i) = dt.ToString("yyyy/MM/dd HH:mm ") & files(i).FullName
>                Next
>
>                'Sort the array (ends up sorting by date)
>                Array.Sort(datesAndNames)
>
>                'Return file name with date trimmed off
>                Return datesAndNames(files.Length - 1).Substring(17)
>
>            Catch ex As Exception
>                Throw (New Exception)
>            End Try
>        End Function
>
Previous
Reply
Map
View

Click here to load this message in the networking platform