开发者

Path of recent creation time of a single file using C#

How to get the path of开发者_StackOverflow社区 the recent or latest file based on creation time (say 'test.xml) located in many sub directories within a main directory.


You can use LINQ:

Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)
         .OrderBy(File.GetLastWriteTime)
         .Last()

If you're not using .Net 4.0, change that to

Directory.GetFiles(path, "*", SearchOption.AllDirectories)
         .OrderBy(p => File.GetLastWriteTime(p))
         .Last()

This is somewhat slower, but will work in .Net 3.5.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜