日期:2014-05-17 浏览次数:20744 次
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string filename = "你的文件名";
DriveInfo[] drivers = DriveInfo.GetDrives();
List<FileInfo> files = new List<FileInfo>();
foreach (var di in drivers.Where(x => x.Name != "C:\\" && x.DriveType == DriveType.Fixed))
{
files.AddRange(di.RootDirectory.GetFiles(filename, SearchOption.AllDirectories));
}
string lastfile = files.OrderByDescending(x => x.LastWriteTime).Select(x => x.Name).FirstOrDefault() ?? "";
Console.WriteLine(lastfile);
}
}
}