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


C# DirectoryInfo.OrderBy方法代码示例

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


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

示例1: UpdateNuspecAndAssemblyInfo

		public UpdatePackagesStep UpdateNuspecAndAssemblyInfo()
		{
			var checkPackages =
				new DirectoryInfo(solutionSystemInfo.FolderPath)
					.GetFiles("AssemblyInfo.cs", SearchOption.AllDirectories)
					.Select(Packages.Parse)
					.Where(x => x != null && packagesId.Contains(x.Title))
					.GroupBy(x => x.Title)
					.ToDictionary(k => k.Key, v => new { Versions = v.Select(y => y.PackageVersion), Packages = v.Select(y => y) })
					.Where(x => x.Value.Packages.Any(y => y.HasNuget))
					.ToArray();

			var packagesWithDifferentVersions = checkPackages.Where(x => x.Value.Versions.Distinct().Count() > 1).ToArray();

			if (packagesWithDifferentVersions.Any())
			{
				ConsoleHelper.WriteLine("Packages with different versions to be fixed");

				return new UpdatePackagesStep();
			}

			var packages =
				checkPackages
					.OrderBy(x => x.Key)
					.Select(x => new PackageWithFramework(x.Key, x.Value.Versions.First(), x.Value.Packages))
					.ToArray();

			return new UpdatePackagesStep(solutionSystemInfo, buildAndRevision, packages, previousVersions);
		}
开发者ID:matteomigliore,项目名称:HSDK,代码行数:29,代码来源:04.UpdateNuspecAndAssemblyInfoStep.cs

示例2: StartGrep

 private void StartGrep()
 {
     try
       {
     foreach (var item in options.FilePaths)
     {
       string path = WildcardCharacterHelper.TranslateWildcardDirectoryPath(item);
       if (options.IsSetDirectory)
       {
     GrepDirectory(path);
       }
       else
       {
     if (WildcardCharacterHelper.IsContainsWildcard(path))
     {
       string dir = path;
       if (!path.Contains("\\") && !path.Contains("/"))
       {
         dir = Environment.CurrentDirectory + Path.DirectorySeparatorChar + path;
       }
       FileInfo[] files = new DirectoryInfo(Path.GetDirectoryName(dir)).GetFiles();
       foreach (var file in files.OrderBy(f => f.Name))
       {
         Regex r = new Regex(WildcardCharacterHelper.TranslateWildcardToRegex(path));
         if (r.IsMatch(file.FullName) || r.IsMatch(file.Name))
         {
           GrepFile(file.FullName);
         }
       }
     }
     else
     {
       GrepFile(path);
     }
       }
     }
       }
       catch (ArgumentException ex)
       {
     RaiseCommandLineException(this, new CommandLineException("Path is invalid.", ex));
       }
       catch (CommandLineException ex)
       {
     RaiseCommandLineException(this, ex);
       }
 }
开发者ID:sealong,项目名称:Knifer,代码行数:46,代码来源:GrepCommandLine.cs

示例3: getAllFiles

        /// <summary>
        /// Gets all files from the specified folder
        /// </summary>
        /// <param name="folder">which folder</param>
        /// <param name="order">sort order</param>
        /// <returns>list of all files</returns>
        private List<FileInfo> getAllFiles(String folder, SortOrder order)
        {
            var retVal = new List<FileInfo>();

            if (Directory.Exists(folder))
            {
                var fileInfo = new DirectoryInfo(folder).GetFiles();

                switch (order)
                {
                    case SortOrder.DateDescending:
                        retVal = fileInfo.OrderByDescending(f => f.LastWriteTime).ToList();
                        break;

                    case SortOrder.DateAscending:
                        retVal = fileInfo.OrderBy(f => f.LastWriteTime).ToList();
                        break;

                    case SortOrder.AtoZ:
                        retVal = fileInfo.OrderBy(f => f.Name).ToList();
                        break;

                    case SortOrder.ZtoA:
                        retVal = fileInfo.OrderByDescending(f => f.Name).ToList();
                        break;

                    default:
                        retVal = fileInfo.ToList();
                        break;
                }
            }

            return retVal;
        }
开发者ID:glwu,项目名称:acat,代码行数:40,代码来源:FileBrowserScanner.cs

示例4: LoadBooks

 private void LoadBooks()
 {
     _bookInfos = new List<Book.BookInfo>();
     var bookFolders =  new DirectoryInfo(_path).GetDirectories();//although NTFS may already sort them, that's an implementation detail
     //var orderedBookFolders = bookFolders.OrderBy(f => f.Name);
     var orderedBookFolders = bookFolders.OrderBy(f => f.Name, new NaturalSortComparer<string>());
     foreach (var folder in orderedBookFolders)
     {
         if (Path.GetFileName(folder.FullName).StartsWith("."))//as in ".hg"
             continue;
         if (Path.GetFileName(folder.FullName).ToLower().Contains("xmatter"))
             continue;
         AddBookInfo(folder.FullName);
     }
 }
开发者ID:JohnThomson,项目名称:testBloom,代码行数:15,代码来源:BookCollection.cs

示例5: MakeDirList

 private List<DirectoryInfo> MakeDirList(DirectoryInfo[] dirs)
 {
     var list = new List<DirectoryInfo>();
     foreach (DirectoryInfo dir in dirs.OrderBy(d => d.Name))
     {
         list.Add(dir);
     }
     return list;
 }
开发者ID:Radytz,项目名称:DroppedBoxx,代码行数:9,代码来源:AddFolderPanel.cs

示例6: addPhotoBackup

        /*
         * Created By: Ryan Causey
         * Created Date: 4/4/13
         * Last Edited By:
         * Last Edited Date:
         */
        /// By: Ryan Causey
        /// Edited Julian Nguyen(5/1/13)
        /// <summary>
        /// Adds all the photos from the library into the *hopefully* already created
        /// Recovery Album.
        /// </summary>
        /// <param name="errorReport">ErrorReport object to be updated</param>
        /// <param name="albumUID">UID of the Recovery Album</param>
        /// <returns>The ErrorReport of this action. </returns>
        private ErrorReport addPhotoBackup(ErrorReport errorReport, Guid albumUID)
        {
            if (albumUID == Guid.Empty)
            {
                setErrorReportToFAILURE("Failed to create recovery album", ref errorReport);
                return errorReport;
            }

            // This method of moving the folder to a new path and copying it back into the library works too
            // I'm not yet able to tell which is faster --BS
            // If you use this method, be sure to uncomment out the directory.delete function at the end of the foreach
            // Note also that DirectoryInfo.*() does not guarantee any order to the files
            //String tmpDir = Path.Combine(libraryPath, "..", "backup");
            //Directory.Move(libraryPath, tmpDir);
            //Directory.CreateDirectory(libraryPath);
            //set up a directory info object from the path
            //FileInfo[] files = new DirectoryInfo(tmpDir).GetFiles();

            IEnumerable<FileInfo> libraryDir = new DirectoryInfo(_imagelibraryDirPath).EnumerateFiles();
            // The files in libraryDir will not be sorted...

            //so we'll sort them here by removing the extension and then sorting them numerically
            IEnumerable<FileInfo> sortedFiles = libraryDir.OrderBy(
                fi => int.Parse(Path.GetFileNameWithoutExtension(fi.Name))
                );

            //set up an array of files
            foreach (FileInfo fi in sortedFiles)
            {
                ComplexPhotoData newPicture = new ComplexPhotoData();

                // Compute the hash for this picture, and then check to make sure it is unique
                newPicture.hash = util_getHashOfFile(fi.FullName);
                if (!util_isImageUniqueToAlbum(albumUID, ByteArrayToString(newPicture.hash)))
                {
                    errorReport.reportStatus = ReportStatus.SUCCESS_WITH_WARNINGS;
                    errorReport.description = "Picture is not unique.";
                    errorReport.warnings.Add("Picture is not unique: " + fi.FullName);
                    return errorReport;
                }

                //probably should check that the file extension is supported...
                newPicture.extension = fi.Extension;

                //get a unique ID for this photo and update its
                //data object to reflect this new UID.
                newPicture.UID = util_getNextUID(_imagesRootXml, "picture", "uid", 1);
                // error checking the call
                if (!util_checkIDIsValid(newPicture.UID))
                {
                    setErrorReportToFAILURE("Failed to get a UID for a new picture.", ref errorReport);
                    return errorReport;
                }

                //Change me if you want to start naming the pictures differently in the library.
                String picNameInLibrary = newPicture.UID.ToString() + fi.Extension;

                // Get the refcount (will get zero if the pic is brand new) and increment it.
                newPicture.refCount = _photoBomb_xml.getPhotoRefCount(ByteArrayToString(newPicture.hash), _imagesRootXml);
                newPicture.refCount++;
                // if this is a new picture, we add it to the db
                if (newPicture.refCount == 1)
                {
                    //rename the file
                    fi.MoveTo(Path.Combine(_imagelibraryDirPath, picNameInLibrary));

                    newPicture.fullPath = fi.FullName;

                    util_addImageToImageDB(errorReport, newPicture);
                }
                else
                {
                    // Otherwise, incremented the refcount, change the xml object in memory and it'll be saved shortly.
                    XElement imageNode = null;
                    if (!_photoBomb_xml.getImageNodeFromImageXml(ByteArrayToString(newPicture.hash), _imagesRootXml, out imageNode))
                    {
                        setErrorReportToFAILURE("Failed to get the image node.", ref errorReport);
                        return errorReport;
                    }
                    imageNode.Attribute("refCount").Value = newPicture.refCount.ToString();
                }

                //if adding to the picture database failed
                if (errorReport.reportStatus == ReportStatus.FAILURE)
                {
//.........这里部分代码省略.........
开发者ID:bsanders,项目名称:softeng,代码行数:101,代码来源:PhotoBombBackend.cs


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