darma teja

darma teja

  • NA
  • 496
  • 337.6k

latest and oldest file in a directory

Apr 2 2013 12:05 PM
Hi all,

How to get latest and oldest file in a directory including filter file extension.

I have different files with different file extension in my directory including sub directories.

for example:
in "c:\Darmateja\"
files:
ab.xml created date: 10.10.2010 9:00 AM
cd.xml created date: 10.10.2010 5: 00 PM
ef.xml created date: 10.10.2011  5:00 PM
gh.xls
ij.xls

Now i want to get all files excluded ".xls". I wrote code like this: I am getting all xml file with this code.
Directory.EnumerateFiles(mypath2, "*.*", SearchOption.AllDirectories).Where(n => Path.GetExtension(n) != ".xls").ToList();

Now I want to get latest created dated file and oldest created dated file. How can i do it?

My out put should be :

ab.xml ------10.10.2010 
ef.xml  ------10.10.2011 


Many Thanks

Darma


Answers (2)