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


C# DirectoryInfo.Count方法代码示例

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


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

示例1: compareSourceAndTarget

        //static List<string> source = new List<string>();
        //static List<string> target = new List<string>();
        public static bool compareSourceAndTarget(DirectoryInfo[] source, DirectoryInfo[] target)
        {
            if(source == null) source = new DirectoryInfo(badMP3BasicPath).GetDirectories();
            if(target == null) source = new DirectoryInfo(goodMP3BasicPath).GetDirectories();

            if ((source.Count() != target.Count())) return false;
            int dirs = target.Count();

            for (int i = 0; i < dirs; i++)
            {
                if (source[i].GetDirectories().Count() > 0 &&
                    target[i].GetDirectories().Count() > 0)
                {
                    return compareSourceAndTarget(source[i].GetDirectories(), target[i].GetDirectories());
                }
                else
                {
                    return compareSourceAndTarget(source[i].GetFiles(), target[i].GetFiles());
                }

                if (source[i].Name != target[i].Name)
                    return false;
            }
            return true;
        }
开发者ID:Epibatidin,项目名称:FLUX,代码行数:27,代码来源:Algs.cs

示例2: Index

 public IActionResult Index(int? Page)
 {
     ViewBag.Title = "Index";
     //Get the configured folder files info and sort it by create time.
     var files = new DirectoryInfo(_appsetting.DNXFolder).GetFileSystemInfos("*.html").OrderByDescending(f => f.CreationTime);
     //---Pagenavi start here ---
     //Calculate the number of pages.
     var pnum = Page ?? 1;
     var PageCount = files.Count() / _appsetting.PageNaviNum + (files.Count() % _appsetting.PageNaviNum == 0 ? 0 : 1);
     pnum = pnum > PageCount ? PageCount : (pnum < 1 ? 1 : pnum);
     ViewBag.Page = pnum;
     ViewBag.PageCount = PageCount;
     //Pick up the number of posts which assigned by appsetting.json file.
     var qf = files.Skip((pnum - 1) * _appsetting.PageNaviNum).Take(_appsetting.PageNaviNum);
     //---Pagenavi end here ---
     var blogs = new List<Blog>();
     foreach (var item in qf)
     {
         var tblog = new Blog();
         tblog.Id = item.Name.Split('.').FirstOrDefault();
         tblog.CreateTime = item.CreationTime;
         //The blog content will fill by get request. System.Net.Http.HttpClient object will request the uri which configured by appsetting.json file.
         tblog.Content = (new System.Net.Http.HttpClient()).GetStringAsync("http://" + (_appsetting.RequestDomain == "" ? Request.Host.ToString() : _appsetting.RequestDomain) + "/" + _appsetting.FilePath + "/" + item.Name).Result;
         blogs.Add(tblog);
     }
     return View(blogs);
 }
开发者ID:zhang61go,项目名称:FreeDBlog,代码行数:27,代码来源:HomeController.cs

示例3: doTracking

        public void doTracking(String path, String image, String resultPath)
        {
            FileInfo[] list = new DirectoryInfo(path).GetFiles("*.jpg");
            int posicaoImage=0;

            for (int i = 0; i < list.Count(); i++)
                if (image.Equals(list[i].FullName))
                {
                    posicaoImage = i;
                    break;
                }

            Blob primeiroBlob = getBlobMaisAlto(image);
            Blob trackBlob = primeiroBlob;
            for (int i = posicaoImage; i < list.Count(); i++)
            {
                try
                {
                    trackBlob = tracking(trackBlob, list[i].FullName);

                    if (trackBlob == null)
                        break;
                    else
                        new Bitmap(list[i].FullName).Save([email protected]"\"+i+".png");
                }
                catch (Exception ex)
                {
                }
            }

            trackBlob = getBlobMaisAlto(image);

            for (int i = posicaoImage; i > 0; i--)
            {
                try
                {
                    trackBlob = tracking(trackBlob, list[i].FullName);

                    if (trackBlob == null)
                        break;
                    else
                        new Bitmap(list[i].FullName).Save(resultPath + @"\" + i + ".png");

                }
                catch (Exception ex)
                {
                }
            }
        }
开发者ID:pablovin,项目名称:stardust,代码行数:49,代码来源:StarTrack.cs

示例4: Pack

        private static void Pack(DirectoryInfo[] dirs)
        {
            int numOfPackagesToPack = dirs.Count();
              if(numOfPackagesToPack == 0)
              {
            return;
              }
              mNumOfPackedPackages += numOfPackagesToPack;

              var myDirUtils = new DirUtils();
              System.Diagnostics.Process process = new System.Diagnostics.Process();
              System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
              startInfo.WorkingDirectory = mPackModulesDest;
              startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
              startInfo.FileName = "cmd.exe";

              StringBuilder listOfModules = new StringBuilder();
              foreach(var d in dirs)
              {
            listOfModules.Append(d.FullName + " ");
            Console.WriteLine("packing " + d.FullName);
              }

              startInfo.Arguments = "/C npm pack " + listOfModules;
              process.StartInfo = startInfo;
              process.Start();
              process.WaitForExit();
        }
开发者ID:amirdoron,项目名称:node-flat,代码行数:28,代码来源:Program.cs

示例5: BuildExistingSiteList

        public void BuildExistingSiteList()
        {
            listViewSites.Items.Clear();
            _XAMPPInstallDir = ConfigManager.GetXAMPPInstallDir();
            _XAMPPWebRootPath = Path.Combine(_XAMPPInstallDir, "htdocs");
            _XAMPPApacheVhostsConfigFile = Path.Combine(_XAMPPInstallDir, "apache\\conf\\extra\\httpd-vhosts.conf");

            if (!CheckSettings())
            {
                return;
            }

            _vhostsManager = new ApacheVhostsConfigManager(_XAMPPApacheVhostsConfigFile, _XAMPPWebRootPath);

            listViewSites.Items.Clear();
            List<VhostsEntry> vhostEntries = _vhostsManager.GetVHostEntries();
            List<HostsEntry> hostsEntries = _hostsManager.GetHostsEntries();
            List<DirectoryInfo> sites = new DirectoryInfo(_XAMPPWebRootPath).GetDirectories("*", SearchOption.TopDirectoryOnly).ToList();

            foreach (VhostsEntry vHostEntry in vhostEntries)
            {
                if (hostsEntries.Count(p => p.DomainName == vHostEntry.ServerName) > 0 ||
                    sites.Count(p => p.Name == vHostEntry.ServerName) > 0)
                {
                    ListViewItem lvi = new ListViewItem(vHostEntry.ServerName);
                    lvi.SubItems.Add("OK");
                    listViewSites.Items.Add(lvi);
                }
            }
        }
开发者ID:Alexander077,项目名称:XAMPPSiteManager,代码行数:30,代码来源:FormMain.cs

示例6: ParsePath

        private static void ParsePath(int pathId, string path, IList<string> validFileExtensions)
        {
            Logger.Info("Scanning Path {0} for files", path);
            var files = new DirectoryInfo(path).GetFiles("*", SearchOption.AllDirectories);
            Logger.Debug("Got {0} files in path {1}", files.Count(), path);

            foreach (var file in files)
            {
                if (!validFileExtensions.Contains(file.Extension))
                {
                    Logger.Trace("Invalid file extension: {0} on file {1}. Skipping", file.Extension, file.FullName);
                    continue;
                }

                lock (ParserStatusLockObject)
                {
                    if (!ParserStatus.ContainsKey(file.ToString()))
                    {
                        ParserStatus.Add(file.FullName, new ParseStatus(file.FullName));
                    }
                }

                ProcessFile(pathId, path, file.FullName);
            }
        }
开发者ID:MichelZ,项目名称:TVJunkie,代码行数:25,代码来源:Parser.cs

示例7: ShippingShouldNotBlockLogFileRolling

        public void ShippingShouldNotBlockLogFileRolling()
        {
            Process shipper = null;
            Process processWithLogFileRolling = null;

            DeleteOldLogFiles();

            File.Delete("LogSearchShipper.exe.config.bak");
            File.Move("LogSearchShipper.exe.config", "LogSearchShipper.exe.config.bak");
            File.Move("LogSearchShipper.exe.config.ShipDummyService", "LogSearchShipper.exe.config");
            try
            {
                shipper = ProcessUtils.StartProcess(Environment.CurrentDirectory + @"\LogSearchShipper.exe",
                    "-instance:integrationtest001");
                processWithLogFileRolling = ProcessUtils.StartProcess(Environment.CurrentDirectory + @"\DummyServiceWithLogRolling.exe", "");

                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10));

                //There should be 6 DummyServiceWithLogRolling.log.* files, unless the shipper has blocked file rolling
                var logFiles =
                    new DirectoryInfo(Environment.CurrentDirectory).GetFiles("DummyServiceWithLogRolling.log.*");
                Assert.AreEqual(6, logFiles.Count());

            }
            finally
            {
                Utils.ShutdownProcess(shipper);
                Utils.ShutdownProcess(processWithLogFileRolling);

                File.Delete("LogSearchShipper.exe.config");
                File.Move("LogSearchShipper.exe.config.bak", "LogSearchShipper.exe.config");
            }
        }
开发者ID:geffzhang,项目名称:LogSearchShipper,代码行数:33,代码来源:LogFileRollingTests.cs

示例8: UploadTraces

        public static void UploadTraces(string sourceFolderPath, string destinationFolderPath)
        {
            if (Directory.Exists(sourceFolderPath))
            {
                var directoriesToUpload = new DirectoryInfo(sourceFolderPath).GetDirectories("DataBackup*");
                if (directoriesToUpload.Count() == 0)
                {
                    Log($"There are no trace directory starting with DataBackup in {sourceFolderPath}");
                    return;
                }

                var perfResultDestinationFolderName = string.Format("PerfResults-{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now);

                var destination = Path.Combine(destinationFolderPath, perfResultDestinationFolderName);
                foreach (var directoryToUpload in directoriesToUpload)
                {
                    var destinationDataBackupDirectory = Path.Combine(destination, directoryToUpload.Name);
                    if (Directory.Exists(destinationDataBackupDirectory))
                    {
                        Directory.CreateDirectory(destinationDataBackupDirectory);
                    }

                    CopyDirectory(directoryToUpload.FullName, destinationDataBackupDirectory);
                }

                foreach (var file in new DirectoryInfo(sourceFolderPath).GetFiles().Where(f => f.Name.StartsWith("ConsumptionTemp", StringComparison.OrdinalIgnoreCase) || f.Name.StartsWith("Roslyn-", StringComparison.OrdinalIgnoreCase)))
                {
                    File.Copy(file.FullName, Path.Combine(destination, file.Name));
                }
            }
            else
            {
                Log($"sourceFolderPath: {sourceFolderPath} does not exist");
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:35,代码来源:TraceBackup.cs

示例9: HasNonHidden

        public static Boolean HasNonHidden(String path)
        {
            if (!Directory.Exists(path))
            {
                return false;
            }

            IEnumerable<FileInfo> files = new DirectoryInfo(path).GetFiles().Where(x => (x.Attributes & FileAttributes.Hidden) == 0);
            IEnumerable<DirectoryInfo> directories = new DirectoryInfo(path).GetDirectories().Where(x => (x.Attributes & FileAttributes.Hidden) == 0);
            return files.Count() > 0 || directories.Count() > 0;
        }
开发者ID:rashime,项目名称:game-save-linker,代码行数:11,代码来源:DirectoryEx.cs

示例10: NavigationOnDiskService_GetItems_Check_Return_Count

 public void NavigationOnDiskService_GetItems_Check_Return_Count()
 {
     //arrange
     INavigationOnDiskService navigationOnDiskService = new NavigationOnDiskService();
     const string path = @"C:\";
     //act
     var items = navigationOnDiskService.GetItems(path);
     var directories = new DirectoryInfo(path).GetDirectories();
     var files = new DirectoryInfo(path).GetFiles();
     //assert
     Assert.AreEqual(directories.Count() + files.Count(), items.Count);
 }
开发者ID:netwer,项目名称:NavigationOnDisk,代码行数:12,代码来源:NavigationOnDiskProjectUnitTest.cs

示例11: InitLogger

        public static void InitLogger()
        {
            if (!Directory.Exists(LogFolder))
                Directory.CreateDirectory(LogFolder);

            var logs = new DirectoryInfo(LogFolder).GetFiles().OrderBy(s => s.LastWriteTime).ToList();
            while (logs.Count() >= ServerMain.settings.maximumLogs)
            {
                var first = logs.First();
                first.Delete();
                logs.Remove(first);
            }
        }
开发者ID:Josvth,项目名称:KerbalMultiPlayer,代码行数:13,代码来源:Logger.cs

示例12: Main

        static void Main(string[] args)
        {
            InitalizeLog4Net();

            string localDirPath = @"C:\Outils\FileTest\Local";
            string masterDirPath = @"C:\Users\Laurent\Pictures\Photos LIGER\";

            var filesEnumerator = new DirectoryInfo(localDirPath).EnumerateFiles("*", SearchOption.AllDirectories);
            int count = filesEnumerator.Count();

            double totalLength = filesEnumerator.Sum(f => f.Length) / 1024.0 / 1024.0;
            Console.WriteLine("{0} fichiers. Taille totale : {1:0.00} Go, Taille moy. : {2:0.00} mo", count, totalLength / 1024, totalLength / count);

            CancellationTokenSource cts = new CancellationTokenSource();
            var breakTask = Task.Factory.StartNew(() => { BreakExecution(cts); }, cts.Token);

            Repository syncDir = new Repository(localDirPath, cts);
            Console.WriteLine();

            // on recommence, mais cette fois pour la synchro vers un autre repertoire
            cts = new CancellationTokenSource();
            breakTask = Task.Factory.StartNew(() => { BreakExecution(cts); }, cts.Token);
            syncDir.SyncWithMaster(masterDirPath, new SyncOptions() { MaxLocalStorage = FileLength.FromGigaBytes(7) }, cts);

            //var doublons = syncDir.Map.Values
            //    .GroupBy(ci => ci.Sha1String)
            //    .Where(g => g.Count() > 1);

            //int totalDoublons = 0;
            //// affichage des doublons :
            //foreach (var group in doublons)
            //{
            //    foreach (var item in group)
            //    {
            //        Console.WriteLine("{0} : {1}", group.Key, item.FileName);
            //    }
            //    totalDoublons += group.Count();
            //    Console.WriteLine("-------- {0} doublons ---------", group.Count());
            //}

            //Console.WriteLine("-------- {0} doublons au total ---------", totalDoublons);
            Console.WriteLine("Appuyer sur une touche pour fermer cette fenetre.");
            Console.Read();
        }
开发者ID:freekk,项目名称:PhotoSync,代码行数:44,代码来源:Program.cs

示例13: GetFileInfos

 public static IEnumerable<FileInfo> GetFileInfos(string path)
 {
     Queue<string> queue = new Queue<string>();
     queue.Enqueue(path);
     while (queue.Count > 0)
     {
         path = queue.Dequeue();
         try
         {
             foreach (string subDir in Directory.GetDirectories(path))
             {
                 queue.Enqueue(subDir);
             }
         }
         catch (Exception ex)
         {
             Console.Error.WriteLine(ex);
         }
         FileInfo[] files = null;
         try
         {
             files = new DirectoryInfo(path).GetFiles();
         }
         catch (Exception ex)
         {
             Console.Error.WriteLine(ex);
         }
         if (files != null)
         {
             for (int i = 0; i < files.Count(); i++)
             {
                 yield return files[i];
             }
         }
     }
 }
开发者ID:ivanmonteiro,项目名称:FileUtilities,代码行数:36,代码来源:Util.cs

示例14: Main

        /// <summary>
        /// Primary entry point to the program
        /// </summary>
        static void Main(string[] args)
        {
            //Document the process:
            Console.WriteLine("QuantConnect.ToolBox: AlgoSeek Options Processor ");
            Console.WriteLine("=================================================");
            Console.WriteLine("The AlgoSeek Options Processor transforms AlgoSeek options ticks into the LEAN Algorithmic Trading Engine Data Format.");
            Console.WriteLine("Three parameters are required: ");
            Console.WriteLine("   1> Output resolution of the LEAN data. (either minute, second or hour)");
            Console.WriteLine("   2> Source Directory of Zipped AlgoSeek Options Data.");
            Console.WriteLine("   3> Destination Directory of LEAN Data Folder. (Typically located under Lean/Data)");
            Console.WriteLine(" ");
            Console.WriteLine("NOTE: THIS WILL OVERWRITE ANY EXISTING FILES.");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();

            if (args.Length > 0) _resolution = args[0];
            if (args.Length > 1) _sourceDirectory = args[1];
            if (args.Length > 2) _destinationDirectory = args[2];

            //Validate the user input:
            Validate(_sourceDirectory, _destinationDirectory, _resolution);

            //Remove the final slash to make the path building easier:
            _sourceDirectory = StripFinalSlash(_sourceDirectory);
            _destinationDirectory = StripFinalSlash(_destinationDirectory);

            //Get all the zip files to process
            Console.WriteLine("Counting Files...");
            var zipFiles = new DirectoryInfo(_sourceDirectory).GetFiles("*.zip");
            Console.WriteLine("Processing {0} Files ...", zipFiles.Count());

            // Dummy zip file
            var zipOut = new Ionic.Zip.ZipFile();

            foreach (var zipFile in zipFiles)
            {
                var starttime = DateTime.Now;
                Console.WriteLine("Reading " + zipFile.Name);

                var listTick = new List<TmpTick>();

                using (var reader = Compression.Unzip(zipFile.FullName, out zipOut))
                    while (!reader.EndOfStream)
                    {
                        var tick = new TmpTick(zipFile.Name.Split('.')[1], reader.ReadLine());
                        if (tick.IsInvalid) continue;

                        if (listTick.Count == 0)
                        {
                            listTick.Add(tick);
                            continue;
                        }

                        var lastRoundTime = listTick.Last().Time.RoundDown(_span);

                        if (lastRoundTime == tick.Time.RoundDown(_span))
                        {
                            listTick.Add(tick);
                            continue;
                        }

                        Console.Write("\r" + lastRoundTime.ToString(@"HH\:mm\:ss") + "\t" + listTick.Count + "\t" + (DateTime.Now - starttime).ToString(@"hh\:mm\:ss\.fff"));

                        WriteLeanCsvFiles(listTick);

                        listTick.Add(tick);
                    }

                WriteLeanCsvFiles(listTick);

                CompressLeanCSV(zipFile);

                Console.WriteLine("... done!");
            }

            Console.WriteLine("All done! Press any key to exit.");
            Console.ReadKey();
        }
开发者ID:skyfyl,项目名称:Lean,代码行数:81,代码来源:Program.cs

示例15: BwBusiness_DoWork

        private void BwBusiness_DoWork(object sender, DoWorkEventArgs e)
        {
            Stopwatch directoryStopwatch = new Stopwatch();
            threadCount++;

            do
            {
                //Get available memory
                var computerInfo = new ComputerInfo();
                var availablePhysicalMemory = (decimal)(computerInfo.AvailablePhysicalMemory);
                var totalPhysicalMemory = (decimal)(computerInfo.TotalPhysicalMemory);
                var freeMemRatio = availablePhysicalMemory / totalPhysicalMemory;

                //Memory protection check
                if (freeMemRatio > (decimal).09)
                {
                    bool errorFlag = false;

                    if (!directoryStopwatch.IsRunning)
                    {
                        directoryStopwatch.Start();
                    }

                    //Get file info so that any necessary logging can be written to the
                    //appropriate folder
                    FileInfo fiPeek;
                    fileQueue.TryPeek(out fiPeek);

                    try
                    {
                        Stopwatch swFile = new Stopwatch();
                        swFile.Start();

                        bool isCR2Processing = false;

                        //Keep trying to get a file from the queue
                        FileInfo fi;
                        while (!fileQueue.TryDequeue(out fi) && fileQueue.Count() != 0)
                        {

                        }

                        if (fi != null && File.Exists(fi.FullName))
                        {
                            string filePath = fi.FullName;
                            string directoryPath = fi.DirectoryName;
                            currentDirectory = directoryPath;

                            //Create Subfolders for Processed DNGs and Logs
                            if (fi.Name.ToLower().Contains(".dng"))
                            {
                                fi.Directory.CreateSubdirectory("Dual ISO DNG");
                            }
                            if (fi.Name.ToLower().Contains(".cr2"))
                            {
                                isCR2Processing = true;
                                fi.Directory.CreateSubdirectory("Dual ISO CR2");
                                fi.Directory.CreateSubdirectory("Dual ISO Original CR2");
                            }
                            fi.Directory.CreateSubdirectory("logs");

                            //Handle condition where application exited before files moved
                            if (File.Exists(fi.FullName.ToLower().Replace(".dng", ".cr2")))
                            {
                                isCR2Processing = true;
                            }

                            //Get initial image path pre-move
                            string initialImagePath = fi.FullName;
                            //Get initial log path pre-move
                            string initialLogPath = initialImagePath + ".log";

                            //Get log directory path
                            string logDirectoryPath = fi.Directory.EnumerateDirectories().Where(
                                d => d.Name.Contains("logs")).FirstOrDefault().FullName;

                            //Get destination log path
                            string destLogPath = fi.Directory.EnumerateDirectories().Where(
                                d => d.Name.Contains("logs")).FirstOrDefault().FullName + "\\" + fi.Name + ".log";

                            //Get destination image path
                            string destImagePath = string.Empty;
                            if (fi.Name.ToLower().Contains(".dng"))
                            {
                                if (!isCR2Processing)
                                {
                                    destImagePath = fi.Directory.EnumerateDirectories().Where(
                                        d => d.Name.Contains("Dual ISO DNG")).FirstOrDefault().FullName + "\\" + fi.Name;
                                }
                                else
                                {
                                    destImagePath = fi.Directory.EnumerateDirectories().Where(
                                        d => d.Name.Contains("Dual ISO CR2")).FirstOrDefault().FullName + "\\" + fi.Name;
                                }
                            }
                            else if (fi.Name.ToLower().Contains(".cr2"))
                            {
                                destImagePath = fi.Directory.EnumerateDirectories().Where(
                                    d => d.Name.Contains("Dual ISO Original CR2")).FirstOrDefault().FullName + "\\" + fi.Name;
                            }
//.........这里部分代码省略.........
开发者ID:layibabalola,项目名称:Dual-ISO-Processor,代码行数:101,代码来源:DualISOProcessor.cs


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