|
|
|
start date: Wed, 22 Aug 2007 12:50:04 -0700,
posted on: microsoft.public.dotnet.general
back
| Thread Index |
|
1
OriginalStealth
|
|
2
Kevin Spencer
|
|
3
OriginalStealth
|
How do I get the latest folder created (Help!!!)
I have partial code that works (below) that returns the folders in the
directory to a listbox but it is not sorted by LastCreateDate or
LastWriteDate. I only need to return 1 record (the most recently created
folder to a textbox)
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Try
ListBox1.Items.Clear()
Dim path As String = "S:\Movies\ABC\FMRSST"
For Each f As String In System.IO.Directory.GetDirectories(path)
Dim filename As String = f.Substring(f.LastIndexOf("\") + 1)
Dim sLastWritedate As String =
System.IO.File.GetLastWriteTime(path)
'Dim fn_withoutextn As String = filename.Substring(0,
filename.IndexOf("."))
ListBox1.Items.Add(filename)
Next
Catch ex As System.Exception
End Try
End Sub
thanks in advance
Date:Wed, 22 Aug 2007 12:50:04 -0700
Author:
|
Re: How do I get the latest folder created (Help!!!)
Use the System.IO.Directory.GetCreationTime(path) method to get the creation
time of each directory. Using an integer indexed loop, create a variable
that contains DateTime.MinValue, and compare it to the result of each
Directory. Also create a variable that stores the index in the loop, and
initialize it to 0. When a Directory's Creation Time is greater than the
DateTime variable, set the DateTime variable to the Directory's Creation
Time, and the index variable to the index in the loop. When you've looped
through all Directories, the index variable will contain the index of the
Directory with the latest Creation Time.
--
HTH,
Kevin Spencer
Microsoft MVP
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
"OriginalStealth" wrote in
message news:8611FDF9-D5DA-4796-B8B2-FBE53BFA478B@microsoft.com...
>I have partial code that works (below) that returns the folders in the
> directory to a listbox but it is not sorted by LastCreateDate or
> LastWriteDate. I only need to return 1 record (the most recently created
> folder to a textbox)
>
>
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
>
> Try
> ListBox1.Items.Clear()
> Dim path As String = "S:\Movies\ABC\FMRSST"
>
> For Each f As String In
> System.IO.Directory.GetDirectories(path)
> Dim filename As String = f.Substring(f.LastIndexOf("\") +
> 1)
> Dim sLastWritedate As String =
> System.IO.File.GetLastWriteTime(path)
> 'Dim fn_withoutextn As String = filename.Substring(0,
> filename.IndexOf("."))
> ListBox1.Items.Add(filename)
> Next
> Catch ex As System.Exception
> End Try
> End Sub
>
>
> thanks in advance
>
Date:Thu, 23 Aug 2007 08:05:10 -0400
Author:
|
Re: How do I get the latest folder created (Help!!!)
Thanks Kevin but I forgot to mention that I am two weeks into dotnet with not
formal training. I am sorry to mislead you with my code but I found that
online. Could you or anyone provide code as I am under a tight deadline.
Thanks in advance.
"Kevin Spencer" wrote:
> Use the System.IO.Directory.GetCreationTime(path) method to get the creation
> time of each directory. Using an integer indexed loop, create a variable
> that contains DateTime.MinValue, and compare it to the result of each
> Directory. Also create a variable that stores the index in the loop, and
> initialize it to 0. When a Directory's Creation Time is greater than the
> DateTime variable, set the DateTime variable to the Directory's Creation
> Time, and the index variable to the index in the loop. When you've looped
> through all Directories, the index variable will contain the index of the
> Directory with the latest Creation Time.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
>
> DSI PrintManager, Miradyne Component Libraries:
> http://www.miradyne.net
>
> "OriginalStealth" wrote in
> message news:8611FDF9-D5DA-4796-B8B2-FBE53BFA478B@microsoft.com...
> >I have partial code that works (below) that returns the folders in the
> > directory to a listbox but it is not sorted by LastCreateDate or
> > LastWriteDate. I only need to return 1 record (the most recently created
> > folder to a textbox)
> >
> >
> > Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles Button2.Click
> >
> > Try
> > ListBox1.Items.Clear()
> > Dim path As String = "S:\Movies\ABC\FMRSST"
> >
> > For Each f As String In
> > System.IO.Directory.GetDirectories(path)
> > Dim filename As String = f.Substring(f.LastIndexOf("\") +
> > 1)
> > Dim sLastWritedate As String =
> > System.IO.File.GetLastWriteTime(path)
> > 'Dim fn_withoutextn As String = filename.Substring(0,
> > filename.IndexOf("."))
> > ListBox1.Items.Add(filename)
> > Next
> > Catch ex As System.Exception
> > End Try
> > End Sub
> >
> >
> > thanks in advance
> >
>
>
>
Date:Thu, 23 Aug 2007 08:04:03 -0700
Author:
|
|
|