ls command ls – Listing contents of directory, this utility can list the files and directories and can even list all the status information about them including: date and time of modification or access, permissions, size, owner, group etc.
Sort a File Numerically By default, sort will arrange the data in ascending order. If you want to sort in descending order, reverse the arrangement using the -r option along with the -n flag in the command.
Click the sort option in the top right of the Files area and select Date from the dropdown. Once you have Date selected, you will see an option to switch between descending and ascending order.
I want to get a list of files in a folder sorted by their creation date using C#.
I am using the following code:
if(Directory.Exists(folderpath))
{
DirectoryInfo dir=new DirectoryInfo (folderpath);
FileInfo[] files = dir.GetFiles().OrderBy(p=>p.CreationTime).ToArray();
foreach (FileInfo file in files)
{
......
}
}
This will give the ascending order of the creation time. I actually want get the most recently created file in the first position of my array (descending order).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With