当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.DirectoryInfo.Where方法代码示例

本文整理汇总了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()));
            }
        }
开发者ID:NicoJuicy,项目名称:CLI-Cleanup-IO,代码行数:53,代码来源:Program.cs

示例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);
        }
开发者ID:PolishDev,项目名称:shop-manager,代码行数:21,代码来源:AdministrationController.cs


注:本文中的System.IO.DirectoryInfo.Where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。