473,320 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Sorting Directories

Hi,

I've got a simple:
DirectoryInfo[] dis = d.GetDirectories();
foreach (DirectoryInfo di in dis)

The trouble is I can't find a way to sort or order the directoryinfo[]
array, I've found a way of doing it for files, but for some reason you
can't do the same to directoryinfo.

could some one give me some pointers.

thx

Chris

Jan 29 '07 #1
2 12270
Hi,

Cable wrote:
Hi,

I've got a simple:
DirectoryInfo[] dis = d.GetDirectories();
foreach (DirectoryInfo di in dis)

The trouble is I can't find a way to sort or order the directoryinfo[]
array, I've found a way of doing it for files, but for some reason you
can't do the same to directoryinfo.

could some one give me some pointers.

thx

Chris
Any array can be sorted using the Array.Sort method.
http://msdn2.microsoft.com/en-us/lib...rray.sort.aspx

For example, you can use the Sort( Array, IComparer ) override.
http://msdn2.microsoft.com/en-us/library/aw9s5t8f.aspx

This lets you specify a class implementing the IComparer interface, in
which any criterium can be used for the sorting algorithm.

In .NET 2.0, a nice alternative is the generic version:
http://msdn2.microsoft.com/en-us/library/cxt053xf.aspx

In this override, the comparison algorithm is not defined in a class,
but in a method which is passed as a delegate to the Sort method.

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jan 30 '07 #2

Array.Sort<DirectoryInfo>(dis, new
Comparison<DirectoryInfo>(delegate(DirectoryInfo d1, DirectoryInfo d2) {
return string.Compare(d1.Name, d2.Name); }));

"Cable" <cb****@gmail.comha scritto nel messaggio
news:11**********************@v33g2000cwv.googlegr oups.com...
Hi,

I've got a simple:
DirectoryInfo[] dis = d.GetDirectories();
foreach (DirectoryInfo di in dis)

The trouble is I can't find a way to sort or order the directoryinfo[]
array, I've found a way of doing it for files, but for some reason you
can't do the same to directoryinfo.

could some one give me some pointers.

thx

Chris

Jan 30 '07 #3

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

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
40
by: Elijah Bailey | last post by:
I want to sort a set of records using STL's sort() function, but dont see an easy way to do it. I have a char *data; which has size mn bytes where m is size of the record and n is the...
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...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
8
by: ianaré | last post by:
Hey all, if i use a os.walk() to append files to a list like so... files = root = self.path.GetValue() # wx.TextCtrl input filter = self.fileType.GetValue().lower() # wx.TextCtrl input...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
6
by: Soren | last post by:
Hi, I'd like to read the filenames in a directory, but not the subdirectories, os.listdir() gives me everything... how do I separate the directory names from the filenames? Is there another way...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.