473,698 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorting Directories

Hi,

I've got a simple:
DirectoryInfo[] dis = d.GetDirectorie s();
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 12301
Hi,

Cable wrote:
Hi,

I've got a simple:
DirectoryInfo[] dis = d.GetDirectorie s();
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<Dire ctoryInfo>(dis, new
Comparison<Dire ctoryInfo>(dele gate(DirectoryI nfo d1, DirectoryInfo d2) {
return string.Compare( d1.Name, d2.Name); }));

"Cable" <cb****@gmail.c omha scritto nel messaggio
news:11******** **************@ v33g2000cwv.goo glegroups.com.. .
Hi,

I've got a simple:
DirectoryInfo[] dis = d.GetDirectorie s();
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
2531
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() sorted_feature_vector.sort() #feature_vector.keys()=sorted_feature_vector
7
3261
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)) CType(local4, Short) = CType(src, Short)
40
4285
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 number of records. Both these numbers are known
3
1257
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 to grab the latest copy of data to load into my program. Example:
19
25459
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 sort columns based on the column header the user has clicked in both Ascending and Descending formats.
8
1561
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 not_type = self.not_type.GetValue() # wx.CheckBox input for base, dirs, walk_files in os.walk(root):
1
7188
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 methods or syntax to a less experienced perl coder. I will post links to online resources you can read if necessary. Experienced perl coders might find nothing new or useful contained in this article. Short Review In part one I showed you some...
6
5685
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 of doing this? Thanks!
5
4946
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 there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html Here is some jquery js that I think...
0
8673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8860
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7716
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4365
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.