Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27046

Help with Date comparison method

$
0
0
Details:
  • Unknown # of folder in directory C:\...\releases\?
  • Get the creation dates of those folders.
  • Compare an unknown quantity of folders of their date of creation property.
  • Retreive the folder's name from the list that has the creation date.


Code:

   
Private Sub GetLatestFolder(  )

        Dim createDates As New List(Of Date)  'Folder's corresponding date values
        Dim Folders As New List(Of String)      'Name of Folders themselves
        Dim counter As Integer = 0
        Dim result As Integer = 0  'Result from comparing dates
        Dim version As String  'The unknown version # of the latest folder

        Try
            Dim myFolders As IEnumerable(Of DirectoryInfo) = Directory.GetDirectories("C:\Sound Manager\Design\projects\\releases", "*", SearchOption.TopDirectoryOnly).Select(Function(x) New DirectoryInfo(x))
            For Each fName In myFolders
                createDates.Add(fName.CreationTime())
                Folders(counter) = fName.Name()
                counter = counter + 1
            Next

            If (Folders.Count >= 2) Then
                For i As Integer = 0 To Folders.Count - 1
                    result = Date.Compare(createDates(i), createDates(i + 1))
                Next

            End If


            If result < 0 Then

                version = Folders(1)

            Else

                version = Folders(0)

            End If

Return version


End sub


Viewing all articles
Browse latest Browse all 27046

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>