Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting newest Excel filename from folder
Message
De
25/01/2007 16:05:30
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB.NET 1.1
Divers
Thread ID:
01187847
Message ID:
01189390
Vues:
14
        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
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform