-4

I need to get list of sub-directories from a directory ordered by CreationDate in .Net 3.0

rahul dhawan
  • 37
  • 1
  • 1
  • 4
  • http://stackoverflow.com/q/52842/16391 gives you a way to order the Files in a directory, you would just need to substitute the GetDirectory for GetFile and DirectoryInfo for FileInfo – StingyJack Aug 17 '12 at 16:32

2 Answers2

19

You should be able to use the DirectoryInfo class for this (requires .NET 4):

var di = new DirectoryInfo(theFolder);
var directories = di.EnumerateDirectories()
                    .OrderBy(d => d.CreationTime)
                    .Select(d => d.Name)
                    .ToList();

In .NET 3.0, you could use DirectoryInfo.GetDirectories, then sort the array afterwards using the same logic.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
4

1) You can use Directory.GetDirectories to get a list of paths of all sub-directories.

2) One time got it convert the list of paths into the list of DirectoryInfo objects. Every DirectoryInfo contains FileSystemInfo.CreationTime property.

3) So the last thing that remains is to order a list based on that property.

Tigran
  • 61,654
  • 8
  • 86
  • 123