br****************@gmail.com wrote:
Is there an easy way to loop through directories sorted by, say,
CreationTime or LastAccessTime? It seems like a reasonable
capability, but I don't see it.
Define "easy".
I'm not aware of a single method in .NET that does this. But it should
not be all that hard to use Directory.GetDirectories() to obtain a list
of directories in a given directory, and then sort that list according
to their properties (such as timestamps, as your example).
In the most basic implementation, you would just use an Array.Sort()
overload that takes an IComparer instance, where your IComparer
retrieves the relevant property for each of the two array elements
passed to it. If you're comfortable with generics, you might prefer the
overload that uses a Comparison<Tdelegate.
If you want to only retrieve the property information once for each
directory, you could create a new list of DirectoryInfo instances and
sort that instead. But I think that unless you are dealing with a huge
number of directories, this might be overkill.
Pete