1

I want to get the sub directories list in ascending order on created date means the oldest directory should be first and so on.

List subfolders = Directory.GetDirectories(source).ToList();

LogicalDesk
  • 1,237
  • 4
  • 16
  • 46
  • 1
    Possible duplicate of [getting directory list in creation date order in .Net 3.0](https://stackoverflow.com/questions/12009615/getting-directory-list-in-creation-date-order-in-net-3-0) – Alex K. Jul 06 '17 at 10:32

2 Answers2

1

I think DirectoryInfo.GetDirectories will be more suitable here, you can do like the following:

string source = "source Path here";
DirectoryInfo dInfo = new DirectoryInfo(source);
var subfolders = dInfo.GetDirectories(source).OrderBy(x=>x.CreationTime).ToList();      

Here the result of dInfo.GetDirectories will be of type System.IO.DirectoryInfo[] you can get Name,path or any related from each object of the subfolders

sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
0

You can use the DirectoryInfo. DirectoryInfo contains FileSystemInfo.CreationTime property.

var di = new DirectoryInfo(source);
var subfolders= di.EnumerateDirectories()
                  .OrderBy(d => d.CreationTime)
                  .ToList();
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
Mehmet Topçu
  • 1
  • 1
  • 16
  • 31