472,986 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

Listing Directories by Creation Date

I know that you can list a directories and subdirectories using the
DirectoryInfo Class. However, is it possible to sort the directories by
creation date?

Thank you!
Nov 19 '05 #1
3 1400
you load them into an ArrayList or Array and sort.

-- bruce (sqlwork.com)

"RHPT" <RH**@online.nospam> wrote in message
news:44**********************************@microsof t.com...
I know that you can list a directories and subdirectories using the
DirectoryInfo Class. However, is it possible to sort the directories by
creation date?

Thank you!

Nov 19 '05 #2
Hi,

Yes you can. Create your own class that implements IComparer interface and
use it when calling Array.Sort method. Please fing a code snippet below.

public class DirectoryInfoComparer : System.Collections.IComparer
{
public DirectoryInfoComparer()
{
}

public int Compare(object o1, object o2)
{
System.IO.DirectoryInfo info1 =
(System.IO.DirectoryInfo) o1;
System.IO.DirectoryInfo info2 =
(System.IO.DirectoryInfo) o2;

return DateTime.Compare(
info1.CreationTime,
info2.CreationTime);
}
}
// and test
private void button1_Click(object sender, System.EventArgs e)
{
DirectoryInfoComparer comparer =
new DirectoryInfoComparer();

System.IO.DirectoryInfo info =
new System.IO.DirectoryInfo("c:\\");
System.IO.DirectoryInfo[] infos =
info.GetDirectories();

Array.Sort(infos, comparer);

foreach (System.IO.DirectoryInfo i in infos)
{
listBox1.Items.Add(i.FullName + " : " + i.CreationTime);
}
}
Hope this helps
--
Milosz Skalecki
MCP, MCAD
"RHPT" wrote:
I know that you can list a directories and subdirectories using the
DirectoryInfo Class. However, is it possible to sort the directories by
creation date?

Thank you!

Nov 19 '05 #3
Thank you!!

"Milosz Skalecki" wrote:
Hi,

Yes you can. Create your own class that implements IComparer interface and
use it when calling Array.Sort method. Please fing a code snippet below.

public class DirectoryInfoComparer : System.Collections.IComparer
{
public DirectoryInfoComparer()
{
}

public int Compare(object o1, object o2)
{
System.IO.DirectoryInfo info1 =
(System.IO.DirectoryInfo) o1;
System.IO.DirectoryInfo info2 =
(System.IO.DirectoryInfo) o2;

return DateTime.Compare(
info1.CreationTime,
info2.CreationTime);
}
}
// and test
private void button1_Click(object sender, System.EventArgs e)
{
DirectoryInfoComparer comparer =
new DirectoryInfoComparer();

System.IO.DirectoryInfo info =
new System.IO.DirectoryInfo("c:\\");
System.IO.DirectoryInfo[] infos =
info.GetDirectories();

Array.Sort(infos, comparer);

foreach (System.IO.DirectoryInfo i in infos)
{
listBox1.Items.Add(i.FullName + " : " + i.CreationTime);
}
}
Hope this helps
--
Milosz Skalecki
MCP, MCAD
"RHPT" wrote:
I know that you can list a directories and subdirectories using the
DirectoryInfo Class. However, is it possible to sort the directories by
creation date?

Thank you!

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
19
by: SU News Server | last post by:
I've struggled with this for quite a while and I'm am just not sure what is going on. I have the following code import os def buildList( directory='/Users/mkonrad' ) dirs = listing =...
3
by: Steven Blair | last post by:
Hi, I have a trace log file for a system I am writing. If the creation date is older than 14 days, I have to rename that file (File.Move). The next time a trace message is required a new file is...
3
by: Nathan Young | last post by:
Hello. Perhaps this isn't really a .NET question, but I'm hoping there is an easy solution within .NET/VC++. The problem: I have a directory full of different types of data files and I need...
2
by: Kurt Schroeder | last post by:
I have a simple directoy list bound to a datagrid. I can get the file names, but is there a way to get the file information from system.io.directory. I'd like to get file size, creation date, and...
8
by: gil | last post by:
Is it possible to prevent a browser from listing the entire contents of a folder? The site, is hosted on my ISP with the following layout- site/ "user name from ISP" pagefile (dir)...
2
by: ngr | last post by:
I used to use the DirListox control in VB6 but this is no longer supported in VB.NET. What I want to do: I want to take a directory listing and show any subdirectories in a list. When you click...
4
by: techusky | last post by:
I have a *very* simple script written that displays the directory listing of the current working directory, but I am having some difficulty when I try to change folders. Basically, I have my $dir...
3
by: kimiraikkonen | last post by:
Hi, I'd like to know whether it is possible to know the sub-directories and also files of a domain, especially domains. Does system.net provides such a function? For example: you only know...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.