473,396 Members | 2,002 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,396 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 12277
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.