473,385 Members | 1,523 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,385 software developers and data experts.

Enumerating files in dir sorted by time

Dan
In .NET, what's the most efficient way to enumerate through all the files in
a directory sorted by time (from oldest to newest)?
Nov 16 '05 #1
1 1995
Dan
Here's what I ended up doing. First I build an IComparer class to compare
the LastWriteTime of each FileSystemInfo object in an array. Then I sorted
all the FileSystemInfo objects returned by DirectoryInfo.GetFileSystemInfos.

public class ReverseDateSorter : IComparer
{

// Calls CaseInsensitiveComparer.Compare with the parameters
reversed.
int IComparer.Compare( Object x, Object y )
{
return DateTime.Compare(((FileSystemInfo)x).LastWriteTime ,
((FileSystemInfo)y).LastWriteTime);
}
}
ReverseDateSorter dateSorter = new ReverseDateSorter();
System.IO.DirectoryInfo dir = new DirectoryInfo(@"c:\junk");
FileSystemInfo[] files = dir.GetFileSystemInfos(@"*.*");
Array.Sort(files, dateSorter);

"Dan" <da*@dontspamme.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
In .NET, what's the most efficient way to enumerate through all the files in a directory sorted by time (from oldest to newest)?

Nov 16 '05 #2

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

Similar topics

6
by: yoda | last post by:
This feels like a stupid question but I'll ask it anyway. How can I process files chronologically (newest last) when using os.walk()?
1
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
6
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
1
by: Dan H. | last post by:
Hello, I have an application that requires a collection that is sorted by a double field first, and then by a long field. So, lets say I have an class that has 2 fields called time, priority. I...
2
by: Tony | last post by:
I have this problem - I have a hashtable, containing a list of filenames. Every 60 seconds, I have a thread that enumerates thru this hashtable, and based on some simple logic, some of the items...
2
by: Gary Wessle | last post by:
Hi I am trying to print out the contents of a directory, sorted. **************** the code **************** 1 import os, sys 2 3 if len(sys.argv) < 2: 4 sys.exit("please enter a...
4
by: Khoa Nguyen | last post by:
Hi, I have a requirement to process all files in a directory in chronological order. The os.listdir() function, however, lists the files in random order. Is there a similar function in Python...
10
by: pamelafluente | last post by:
Hi I have a sorted list with several thousands items. In my case, but this is not important, objects are stored only in Keys, Values are all Nothing. Several of the stored objects (might be a...
7
by: =?utf-8?B?5YiY5piK?= | last post by:
Hi, folks, Is it possible to delete an element from a sorted array with O(1) time? Best regards
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.