C#返回文件夹中过去7天修改的文件(LINQ+匿名类型)

发布于 2016-10-18  200 次阅读


            string myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var query =
                from pathname in Directory.GetFiles(myDocuments)
                let LastWriteTime = File.GetLastWriteTime(pathname)
                where LastWriteTime > (DateTime.Now - TimeSpan.FromDays(7))
                orderby LastWriteTime
                select new { Path = pathname, LastWriteTime };//匿名类型的对象构成的集合
            foreach (var file in query)
            {
                rtxtResult.Text += string.Format("LastWriteTime={0},Path={1}", file.LastWriteTime, file.Path);
            }

LoneKing