|
-
Apr 23rd, 2013, 07:19 PM
#1
Thread Starter
Junior Member
Help with Date comparison method
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
Last edited by Anthony123; Apr 23rd, 2013 at 07:28 PM.
-
Apr 23rd, 2013, 07:35 PM
#2
Re: Help with Date comparison method
Code:
'get folder names + sort by creation datetime
Dim Folders As List(Of String) = IO.Directory.GetDirectories("C:\Sound Manager\Design\projects\\releases", "*", IO.SearchOption.TopDirectoryOnly).OrderBy(Function(f) New IO.FileInfo(f).CreationTime).ToList
'get corresponding creation datetimes
Dim createDates As List(Of Date) = Folders.ConvertAll(Function(f) New IO.FileInfo(f).CreationTime)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 23rd, 2013, 07:37 PM
#3
Re: Help with Date comparison method
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.
That doesn't make sense. I assume you mean to sort the folders by their date of creation but what name are you wanting to retrieve? The oldest, the newest, the one that was created nearest to last Tuesday?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Apr 23rd, 2013, 08:15 PM
#4
Thread Starter
Junior Member
Re: Help with Date comparison method
 Originally Posted by dunfiddlin
That doesn't make sense. I assume you mean to sort the folders by their date of creation but what name are you wanting to retrieve? The oldest, the newest, the one that was created nearest to last Tuesday?
The newest one.
-
Apr 23rd, 2013, 08:30 PM
#5
Re: Help with Date comparison method
using my code from post #2, the newest 1 will be Folders.Last
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|