本文整理汇总了C#中System.IO.DirectoryInfo.Where方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.DirectoryInfo.Where方法的具体用法?C# System.IO.DirectoryInfo.Where怎么用?C# System.IO.DirectoryInfo.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了System.IO.DirectoryInfo.Where方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
int daysOld = 7;
string folder = "";
string pattern = "*.*";
System.IO.SearchOption searchOption = System.IO.SearchOption.TopDirectoryOnly;
Arguments CommandLine = new Arguments(args);
if (CommandLine["Help"] != null)
{
Console.Out.WriteLine("-Help, -Folder, -Pattern, -Days");
}
else
{
if (CommandLine["Subdir"] != null)
{
// includeSubDirectories = true;
searchOption = System.IO.SearchOption.AllDirectories;
}
if (CommandLine["Folder"] != null)
{
folder = CommandLine["Folder"];
}
else
{
throw new MissingMemberException("Missing the Folder argument");
}
if (CommandLine["Pattern"] != null)
{
pattern = CommandLine["Pattern"];
}
if (CommandLine["Days"] != null)
{
daysOld = int.Parse(CommandLine["Days"]);
}
var CurrentTime = System.DateTime.UtcNow;
var pre_matched_files = new System.IO.DirectoryInfo(folder).GetFiles(pattern, searchOption);
var matched_files = pre_matched_files.Where(el => el.LastWriteTimeUtc.AddDays(daysOld) < CurrentTime).ToList();
Console.Out.WriteLine(string.Format("Matched {0} files in folder {1}", matched_files.Count(),folder));
foreach (var file in matched_files)
{
Console.Out.WriteLine(string.Format("Deleting {0} ...", file.Name));
file.Delete();
}
Console.Out.WriteLine(string.Format("Deleted {0} files ", matched_files.Count()));
}
}
示例2: ErrorLog
public ActionResult ErrorLog(string log)
{
var logs = new System.IO.DirectoryInfo(Server.MapPath("~/App_Data")).GetFiles("*.log")
.OrderByDescending(o => o.LastWriteTime)
.Take(10)
.ToDictionary(f => f.Name, f => f.FullName);
string[] selected = { "Select a log file to view..." };
if (!string.IsNullOrWhiteSpace(log))
{
var file = logs.Where(l => l.Key == log).FirstOrDefault();
selected = System.IO.File.ReadAllLines(file.Value);
}
ErrorLogModel model = new ErrorLogModel() {
LogFiles = logs.Select(l => l.Key).ToArray(),
SelectedLog = selected
};
return View("ErrorLog", model);
}