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();
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();
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
You can use the DirectoryInfo
. DirectoryInfo
contains FileSystemInfo.CreationTime
property.
var di = new DirectoryInfo(source);
var subfolders= di.EnumerateDirectories()
.OrderBy(d => d.CreationTime)
.ToList();