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


C# DirectoryInfo.ForEach方法代码示例

本文整理汇总了C#中System.IO.DirectoryInfo.ForEach方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.ForEach方法的具体用法?C# DirectoryInfo.ForEach怎么用?C# DirectoryInfo.ForEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.ForEach方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFile

        public Message GetFile()
        {
            Message message = null;

            var uriSegments = webContext.GetRequestUri().Segments.ToList().Select(u => u.TrimEnd('/')).ToList();
            uriSegments.RemoveRange(0, 2);
            var path = uriSegments.Aggregate(config.AppDir, Path.Combine);

            if (config.AppDir.Equals(path, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new SecurityAccessDeniedException();
            }

            try
            {
                if (File.Exists(path))
                {
                    using (var fileStream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        var memoryStream = new MemoryStream((int)Math.Max(fileStream.Length, 10485760));
                        fileStream.CopyTo(memoryStream, memoryStream.Capacity);
                        memoryStream.Seek(0, SeekOrigin.Begin);
                        message = webContext.CreateStreamResponse(memoryStream, "application/octet-stream");
                    }
                }

                else if (Directory.Exists(path))
                {
                    var memoryStream = new MemoryStream();
                    var outputStream = new StreamWriter(memoryStream);
                    outputStream.NewLine = "\n";

                    var fileSystemInfos = new DirectoryInfo(path).GetFileSystemInfos().OrderBy(i => i is FileInfo).ToList();

                    fileSystemInfos.ForEach(info =>
                    {
                        var left = string.Format("{0}{1}", info.Name, (info is DirectoryInfo) ? "/" : String.Empty);
                        var right = info is DirectoryInfo ? "-" : Utility.GetFileSizeString((info as FileInfo).Length);
                        outputStream.WriteLine(left + new String(' ', Math.Max(8, 46 - left.Length - right.Length)) + right);
                    });

                    outputStream.Flush();
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    message = webContext.CreateStreamResponse(memoryStream, "text/plain");
                }
            }
            catch (Exception ex)
            {
                webContext.SetOutgoingResponse(HttpStatusCode.InternalServerError, ex.ToString());
            }
            return message;
        }
开发者ID:kirannadell,项目名称:ironfoundry,代码行数:52,代码来源:FilesService.cs

示例2: Initialize

        public static void Initialize()
        {
            var pluginContainers = new DirectoryInfo(HostingEnvironment.MapPath("~/Plugins"))
                .GetFiles("*.dll", SearchOption.TopDirectoryOnly)
                .Select(f => new
                {
                    //Assembly = AppDomain.CurrentDomain.Load(File.ReadAllBytes(f.FullName)),
                    Assembly = Assembly.Load(AssemblyName.GetAssemblyName(f.FullName)),
                    Name = f.Name
                }).ToList();
            pluginContainers.ForEach(pc => BuildManager.AddReferencedAssembly(pc.Assembly));
            pluginContainers.ForEach(pc => Register(pc.Name, pc.Assembly));

            HostingEnvironment.RegisterVirtualPathProvider(new AssemblyResourceProvider());

            pluginContainers.SelectMany(pc => pc.Assembly.GetTypes())
                            .Where(t => "Bootstrapper".Equals(t.Name, StringComparison.OrdinalIgnoreCase))
                            .Select(t => t.GetMethod("Init", BindingFlags.Static | BindingFlags.Public))
                            .Where(mi => mi != null && !mi.GetParameters().Any() && !mi.IsGenericMethodDefinition)
                            .Select(mi => mi.Invoke(null, null))
                            .ToList();
        }
开发者ID:mihasic,项目名称:MyPlayground,代码行数:22,代码来源:PreApplicationInit.cs

示例3: Build

        public void Build()
        {
            //strCommandParameters are parameters to pass to program
            var parameters = "\"{0}\" /t:build /m:4 /nr:true /nologo /p:CustomAfterMicrosoftCommonTargets=C:\\CodeBlamer\\filter.targets";
            var path = GetVersionPath();

            var cdCommand = string.Format("C: && cd {0}", path);
            var buildCommand = "C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe " + string.Format(parameters, GetSolutionName());

            CommandExtensions.Run(new string[] {cdCommand, buildCommand});

            var files = new DirectoryInfo(GetVersionPath()).SearchFor("System.Core.dll");
            files.ForEach(x => x.Delete());
        }
开发者ID:pauloortins,项目名称:CodeBlamer,代码行数:14,代码来源:Solution.cs

示例4: Convert2CustomCSV

        /// <summary>
        /// Convert LEAN data to custom data
        /// </summary>
        /// <param name="OutputResolution">Output resoltution for intraday cases (hour/minute/second)</param>
        /// <returns></returns>
        private static async Task Convert2CustomCSV(string OutputResolution)
        {
            var symbols = new DirectoryInfo(_settings.OutputFolder + @"/" + _settings.SecurityType + @"/bra/" + OutputResolution + @"/")
                .GetDirectories().ToList();

            if (_settings.InstrumentList.Length > 0) symbols.RemoveAll(s => !_settings.InstrumentList.Contains(s.Name.ToUpper()));

            if (symbols.Count == 0)
            {

            }

            var sum = 0.0;
            var total = 0.0;
            symbols.ForEach(d => total += d.GetFiles().Sum(f => f.Length));
            
            var roottime = DateTime.Now;
            Console.WriteLine("\r" + symbols.Count + " symbol directories to read (" + (total / 1024 / 1024).ToString("000.00") + " MB).\t" + roottime);

            foreach (var symbol in symbols)
            {
                var starttime = DateTime.Now;
                var factors = GetTickerFactors(symbol.Name);
                var zipfiles = symbol.GetFiles("*.zip").ToList();
                var csvFile = new FileInfo(symbol.Name.ToUpper() + "_" + _settings.OutputResolution + ".csv");
                if (csvFile.Exists) csvFile.Delete();

                foreach (var zipfile in zipfiles)
                {
                    var date = zipfile.Name.ToDateTime();
                    var factor = factors.FirstOrDefault(kvp => kvp.Key >= date);

                    File.AppendAllLines(csvFile.FullName, (await ReadAsyncZipFile(zipfile)).Select(l =>
                    {
                        var data = l.Split(',');

                        return symbol.Name.ToUpper() + ";" +
                            date.AddMilliseconds(data[0].ToInt64()).ToString(@"dd/MM/yyyy;HH\:mm\:ss") + ";" +
                            Math.Round(data[1].ToDecimal() * factor.Value / 10000, 2).ToString("0.00", _ptBR) + ";" +
                            Math.Round(data[2].ToDecimal() * factor.Value / 10000, 2).ToString("0.00", _ptBR) + ";" +
                            Math.Round(data[3].ToDecimal() * factor.Value / 10000, 2).ToString("0.00", _ptBR) + ";" +
                            Math.Round(data[4].ToDecimal() * factor.Value / 10000, 2).ToString("0.00", _ptBR) + ";" +
                            (data.Length == 6 ? data[5] : data[6] + ";" + data[5]);

                    }).ToArray());

                    sum += zipfile.Length;
                }

                Console.Write("\r" + (sum / total).ToString("0.00%") + "\t" + symbol.Name.ToUpper() + ": \t" + zipfiles.Count +
                " days were read/written in " + (DateTime.Now - starttime).ToString(@"ss\.ff") + " secs.\t");
            }

            // For options and futures
            var csvFiles = new DirectoryInfo(Environment.CurrentDirectory).GetFiles("*_" + _settings.OutputResolution + ".csv");

            if (csvFiles.Count() > 0)
            {
                sum = 0.0;
                total = csvFiles.Sum(f => f.Length);
                Console.WriteLine("Zipping " + (total / 1024 / 1024).ToString("000.00") + " MB");

                csvFiles.GroupBy(g =>
                {
                    if (_settings.SecurityType == "equity") return g.Name.Replace(".csv", ".zip");
                    if (_settings.SecurityType == "futures") return g.Name.Substring(0, 3).ToUpper() + "FUT" + "_" + _settings.OutputResolution + ".zip";

                    var type = ("ABCDEFGHIJKL".Contains(g.Name[4]) ? "_C" : "_P") + "_" + _settings.OutputResolution + ".zip";
                    return g.Name.Substring(0, 4) + type;
                })
                    //.ToList().ForEach(f =>
                    //{
                    //    var outputfile = new FileInfo(f.Key);
                    //    if (outputfile.Exists) outputfile.Delete();

                    //    Compression.Zip(outputfile.FullName);

                    //    using (var z = new FileStream(outputfile.FullName, FileMode.Create))

                    //    using (var a = new ZipArchive(z, ZipArchiveMode.Create, true))
                    //        f.ToList().ForEach(csvFile =>
                    //        {
                    //            a.CreateEntryFromFile(csvFile.FullName, csvFile.Name, CompressionLevel.Optimal);
                    //            csvFile.Delete();
                    //            sum += csvFile.Length;
                    //            Console.Write("\r" + (sum / total).ToString("0.00%") + "\tLast zippped file:\t" + csvFile.Name.ToUpper());
                    //        });
                    //})
                    ;
            }
            Console.WriteLine("\r\n... exiting routine at " + DateTime.Now);
        }
开发者ID:AlexCatarino,项目名称:ToolBox,代码行数:97,代码来源:Program.cs

示例5: Tick2Bar

        private static async Task Tick2Bar()
        {
            throw new NotImplementedException();
        
            string submenu;
            double periodDbl;
            
            var periodDic = new Dictionary<string, double> { { "hour", 36e4 }, { "minute", 6e4 }, { "second", 1e3 } };
            
            Console.WriteLine(submenu = "\rChoose period: hour, minute or second. exit to return to Main.");

            var period = Console.ReadLine().ToLower();

            while (!periodDic.TryGetValue(period, out periodDbl))
            {
                if (period == "exit") { Console.WriteLine(_menu); return; }
                Console.WriteLine("Invalid period: " + period + "\r\n" + submenu);
                period = Console.ReadLine().ToLower();
            }

            var dirs = new DirectoryInfo(_settings.InputFolder + @"\"+ _settings.SecurityType + @"\bra\tick\").GetDirectories().ToList();
            
            var sum = 0.0;
            var total = 0.0;
            dirs.ForEach(d => { total += d.GetFiles().Sum(f => f.Length); Console.Write("\r" + d.Name.ToUpper() + " " + (total / 1024 / 1024).ToString("0.00")); });
            Console.WriteLine("\r\n" + dirs.Count + " symbol directories to read.\t" + DateTime.Now);

            foreach (var dir in dirs)
            {
                var starttime = DateTime.Now;
                var outdir = Directory.CreateDirectory(dir.FullName.Replace("tick", period));
                var zipfiles = dir.GetFiles("*.zip").ToList();
                
                foreach (var zipfile in zipfiles)
                {
                    var output = new List<string>();
                    var data = await ReadAsyncZipFile(zipfile);

                    var ticks = double.Parse(data.First().Split(',')[0]);
                    ticks = ticks - ticks % 36e6 + 7.5 * 36e5;

                    // Group by period
                    data.GroupBy(d =>
                        {
                            var totalseconds = Math.Min(ticks, double.Parse(d.Split(',')[0]));
                            return (totalseconds - (totalseconds % periodDbl)).ToString();
                        })
                        // For each period, define bar and save
                        .ToList().ForEach(t =>
                        {
                            var price = t.Select(l => l.Split(',')[1].ToDecimal()).ToList();
                            var qunty = t.Select(l => l.Split(',')[2].ToDecimal()).ToList().Sum();
                            var volfin = t.Select(l => { var d = l.Split(','); return d[1].ToDecimal() * d[2].ToDecimal(); }).ToList().Sum() / 10000;
                            output.Add(t.Key + "," + price.First() + "," + price.Max() + "," + price.Min() + "," + price.Last() + "," + qunty + "," + volfin);
                        });

                    await Task.Factory.StartNew(() =>
                        {
                            var newFile = zipfile.FullName.Replace("tick", period);
                            var csvFile = new FileInfo(newFile.Replace("trade.zip", dir.Name + "_" + period + "_trade.csv"));

                            File.WriteAllLines(csvFile.FullName, output);

                            using (var z = new FileStream(newFile, FileMode.Create))
                            //using (var a = new ZipArchive(z, ZipArchiveMode.Create))
                            //    a.CreateEntryFromFile(csvFile.FullName, csvFile.Name, CompressionLevel.Optimal);

                            csvFile.Delete();
                        });
                    sum += zipfile.Length;
                }

                Console.Write("\r" + (sum / total).ToString("0.00%") + "\t" + dir.Name.ToUpper() + ": \t" + zipfiles.Count +
                    " days were read/written in " + (DateTime.Now - starttime).ToString(@"ss\.ff") + " secs.\t");
            }
            Console.WriteLine("\r\n... exiting routine at " + DateTime.Now);
        }
开发者ID:AlexCatarino,项目名称:ToolBox,代码行数:77,代码来源:Program.cs

示例6: UpdateFolderItems

 private void UpdateFolderItems(string path, string name)
 {
     if (Directory.Exists(path))
     {
         var mobile = new DirectoryInfo(path).GetFileSystemInfos().ToList();
         mobile.ForEach(f => AddOrUpdate(f, System.IO.Path.Combine(path, f.Name), name));
     }
 }
开发者ID:danuw,项目名称:Responsive-Design-Explorer,代码行数:8,代码来源:ResponsiveDirectoryInfo.cs

示例7: Otimizar

        /// <summary>
        /// Executa a Otimização.
        /// </summary>
        /// <param name="caminhoBibliotecaJs"></param>
        /// <param name="caminhoTestesJs"></param>
        /// <returns>
        /// Verdadeiro se encontrar melhoria
        /// </returns>
        public bool Otimizar(string caminhoBibliotecaJs, string caminhoTestesJs)
        {
            bool otimizou = false;

            _caminhoScriptTestes = caminhoTestesJs;
            _caminhoBiblioteca = caminhoBibliotecaJs;

            Console.WriteLine(string.Format("Iniciando Otimização do {0}", caminhoBibliotecaJs));
            Console.WriteLine(string.Format("    SetTimeout {0}", _usarSetTimeout));
            Console.WriteLine(string.Format("    Heuristica {0}", Heuristica));

            _javascriptHelper = new JavascriptHelper(_diretorioFontes, _usarSetTimeout, false);
            _javascriptHelper.ConfigurarGeracao();

            var sw = new Stopwatch();
            sw.Start();
            if(Heuristica == "GA")
                otimizou = OtimizarUsandoGa();
            else if(Heuristica == "RD")
                otimizou = OtimizarUsandoRd();
            else if (Heuristica == "HC")
                otimizou = OtimizarUsandoHc();
            else if (Heuristica == "HCF")
                otimizou = OtimizarUsandoHcPorFuncao();
            else
                throw new ApplicationException(string.Format("Heurística ainda não definida. {0}", Heuristica));

            #region Gera o CSV da rodada

            var myExport = new CsvExport();

            myExport.AddRow();
            myExport["Rodada"] = RodadaGlobalExterna;
            myExport["Individuo"] = MelhorIndividuo.Arquivo;
            myExport["Operacao"] = MelhorIndividuo.CriadoPor;
            myExport["Fitness"] = MelhorIndividuo.Fitness;
            myExport["Tempo"] = MelhorIndividuo.TempoExecucao;
            myExport["Testes"] = MelhorIndividuo.TestesComSucesso;

            myExport.ExportToFile("rodadas.csv");

            #endregion

            #region limpa o diretório de execução.

            var files = new DirectoryInfo(_diretorioExecucao).EnumerateFiles("*.js").ToList();

            files.ForEach(f => f.Delete());

            #endregion

            sw.Stop();
            Console.WriteLine("  Tempo total: {0}", sw.Elapsed.ToString(@"hh\:mm\:ss\,ffff"));

            return otimizou;
        }
开发者ID:ffarzat,项目名称:ConsoleComV8,代码行数:64,代码来源:Otimizador.cs

示例8: compileIncludeUtilityLib

        /// <summary>
        /// needs a tidyup.. and not tested
        /// </summary>
        /// <param name="utility"></param>
        /// <param name="strInclude"></param>
        void compileIncludeUtilityLib(string utility, string strInclude)
        {
            var utilityDir = string.Format(@"{0}\utility", utility);
            var objFileName = "";

            if (Directory.Exists(utilityDir))
            {
                var utilityFileInfo = new DirectoryInfo(utilityDir).GetFiles().ToList();
                utilityFileInfo.ForEach(e =>
                {
                    if (e.Extension.Equals(".c"))
                    {
                        message("gcc " + e.Name);
                        objFileName = e.FullName + ".o";
                        runProcess(info.Gcc, string.Format(StringConst.GCC_INCLUDE_LIB, new object[] { info.Board.Mcu, info.Board.FCpu, strInclude, e.FullName, objFileName }), true);
                        objLinker.Append(objFileName + " ");

                    }
                });
                utilityFileInfo.ForEach(e =>
                {
                    if (e.Extension.Equals(".cpp"))
                    {
                        message("gpp " + e.Name);
                        objFileName = e.FullName + ".o";
                        runProcess(info.Gpp, string.Format(StringConst.GCC_INCLUDE_LIB, new object[] { info.Board.Mcu, info.Board.FCpu, strInclude, e.FullName, objFileName }), true);
                        objLinker.Append(objFileName + " ");

                    }
                });
            }


        }
开发者ID:DiLRandI,项目名称:ArduinoLibrary,代码行数:39,代码来源:Compiler.cs

示例9: Main

        private static void Main(string[] args)
        {
            StaticConfiguration.DisableErrorTraces = false;

            Console.WriteLine("Sandra.Snow : " + DateTime.Now.ToString("HH:mm:ss") + " : Begin processing");

            try
            {
                var commands = args.Select(x => x.Split('=')).ToDictionary(x => x[0], x => x[1]);

                if (commands.ContainsKey("debug"))
                {
                    DebugHelperExtensions.EnableDebugging();
                }

                if (commands.ContainsKey("vsdebug"))
                {
                    DebugHelperExtensions.WaitForContinue();
                }

                string currentDir;

                if (commands.ContainsKey("config"))
                {
                    currentDir = new FileInfo(commands["config"]).DirectoryName;
                }
                else
                {
                    currentDir = Path.GetDirectoryName(typeof(Program).Assembly.Location);
                }

                currentDir.OutputIfDebug(prefixWith: " - Current directory: ");

                var settings = CreateSettings(currentDir);

                var extensions = new HashSet<string>(new[] { ".md", ".markdown" }, StringComparer.OrdinalIgnoreCase);
                var files = new DirectoryInfo(settings.Posts).EnumerateFiles("*", SearchOption.AllDirectories)
                                                             .Where(x => extensions.Contains(x.Extension));

                SetupOutput(settings);

                StaticPathProvider.Path = settings.CurrentDir;
                SnowViewLocationConventions.Settings = settings;

                var posts = files.Select(x => PostParser.GetFileData(x, settings))
                                 .OrderByDescending(x => x.Date)
                                 .Where(x => x.Published != Published.Private && !(x is Post.MissingPost))
                                 .ToList();
                var pages = new DirectoryInfo(settings.Pages).EnumerateFiles("*", SearchOption.AllDirectories)
                                                             .Select(x => PagesParser.GetFileData(x, settings))
                                                             .OrderByDescending(x => x.Date)
                                                             .Where(x => x.Published != Published.Private && !(x is Post.MissingPost))
                                                             .ToList();

                posts.SetPostUrl(settings);
                pages.SetPostUrl(settings);
                posts.UpdatePartsToLatestInSeries();

                TestModule.Posts = posts;
                TestModule.Pages = pages;
                TestModule.Drafts = posts.Where(x => x.Published == Published.Draft).ToList();
                TestModule.Categories = CategoriesPage.Create(posts);
                TestModule.PostsGroupedByYearThenMonth = ArchivePage.Create(posts);
                TestModule.MonthYear = ArchiveMenu.Create(posts);
                TestModule.Settings = settings;

                var browserComposer = new Browser(with =>
                {
                    with.Module<TestModule>();
                    with.RootPathProvider<StaticPathProvider>();
                    with.ViewEngines(typeof(SuperSimpleViewEngineWrapper), typeof(RazorViewEngine));
                });

                // Compile all Posts and pages
                posts.ForEach(x => ComposeParsedFiles(x, settings.PostsOutput, browserComposer));
                pages.ForEach(x => ComposeParsedFiles(x, settings.PagesOutput, browserComposer));

                // Compile all Drafts
                var drafts = posts.Where(x => x.Published == Published.Draft).ToList();
                drafts.ForEach(x => ComposeDrafts(x, settings.PostsOutput, browserComposer));

                // Compile all static files
                foreach (var processFile in settings.ProcessFiles)
                {
                    var success =
                        ProcessFile(processFile, settings, posts, browserComposer);

                    if (!success)
                    {
                        break;
                    }
                }

                foreach (var copyDirectory in settings.CopyDirectories)
                {
                    var sourceDir = (settings.ThemesDir + Path.DirectorySeparatorChar + settings.Theme + Path.DirectorySeparatorChar + copyDirectory);

                    var destinationDir = copyDirectory;

                    if (copyDirectory.Contains(" => "))
//.........这里部分代码省略.........
开发者ID:sgrassie,项目名称:Sandra.Snow,代码行数:101,代码来源:Program.cs


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