• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SearchOption类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SearchOption的典型用法代码示例。如果您正苦于以下问题:C# SearchOption类的具体用法?C# SearchOption怎么用?C# SearchOption使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SearchOption类属于命名空间,在下文中一共展示了SearchOption类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetDirectoryFiles

        /// <summary>
        /// A safe way to get all the files in a directory and sub directory without crashing on UnauthorizedException
        /// </summary>
        /// <param name="rootPath">Starting directory</param>
        /// <param name="patternMatch">Filename pattern match</param>
        /// <param name="searchOption">Search subdirectories or only top level directory for files</param>
        /// <returns>List of files</returns>
        public static IEnumerable<string> GetDirectoryFiles(string rootPath, string patternMatch, SearchOption searchOption)
        {
            IEnumerable<string> foundFiles = Enumerable.Empty<string>(); // Start with an empty container

            if (searchOption == SearchOption.AllDirectories)
            {
                try
                {
                    IEnumerable<string> subDirs = Directory.EnumerateDirectories(rootPath);
                    foreach (string dir in subDirs)
                    {
                        try
                        {
                            foundFiles = foundFiles.Concat(GetDirectoryFiles(dir, patternMatch, searchOption)); // Add files in subdirectories recursively to the list
                        }
                        catch (UnauthorizedAccessException) { } // Incase we have an access error - we don't want to mask the rest
                    }
                }
                catch (UnauthorizedAccessException) { } // Incase we have an access error - we don't want to mask the rest
            }

            try
            {
                foundFiles = foundFiles.Concat(Directory.EnumerateFiles(rootPath, patternMatch)); // Add files from the current directory to the list
            }
            catch (UnauthorizedAccessException) { } // Incase we have an access error - we don't want to mask the rest

            return foundFiles; // This is it finally
        }
开发者ID:hoeness2,项目名称:mcebuddy2,代码行数:36,代码来源:FilePaths.cs


示例2: Search

 public ActionResult Search(SearchOption searchOption, string searchText)
 {
     switch ((int)searchOption)
     {
         case 0:
             // search by Title Name
             return RedirectToAction("/GetTitlesByName", new { titleName = searchText });
             break;
         case 1:
             // search by Genre
             return RedirectToAction("/GetTitlesByGenre", new { genre = searchText });
             break;
         case 2:
             // search by Language
             return RedirectToAction("/GetTitlesByLanguage", new { language = searchText });
             break;
         case 3:
             // search by Participant
             return RedirectToAction("/GetTitlesByParticipant", new { participant = searchText });
             break;
         default:
             // All
             return RedirectToAction("/GetAllTitles/");
             break;
     }
 }
开发者ID:RK109,项目名称:ASP.Net-MVC-4-sample-app-with-EF5.0,代码行数:26,代码来源:TitlesController.cs


示例3: GetDirectories

        public static IEnumerable<string> GetDirectories(string path, SearchOption option)
        {
            IEnumerable<string> dirs = null;

            try
            {
                dirs = Directory.EnumerateDirectories(path);
                //dirs = Directory.GetDirectories(path).ToList();
            }
            catch (UnauthorizedAccessException)
            {
            }

            if (dirs != null)
            {
                foreach (var dir in dirs)
                {
                    if (option == SearchOption.AllDirectories)
                    {
                        foreach (var x in GetDirectories(dir, option))
                        {
                            yield return x;
                        }
                    }

                    yield return dir;
                }
            }
        }
开发者ID:jgennari,项目名称:git-ls,代码行数:29,代码来源:DirectoryTools.cs


示例4: GetFiles

 public static String[] GetFiles(
     string folder,
     string jobExtension,
     SearchOption searchOption)
 {
     return MyDirectory.GetFiles(folder, jobExtension, searchOption);
 }
开发者ID:ProximoSrl,项目名称:Jarvis.DocumentStore,代码行数:7,代码来源:DsDirectory.cs


示例5: GetFileFullNameListByKeyword

        //根据关键字获得文件全名列表
        public static string GetFileFullNameListByKeyword(string strFolderPath, string strKeyword, string searchPattern, SearchOption searchOption)
        {
            string strResult = "";

            DirectoryInfo directoryInfo = new DirectoryInfo(strFolderPath);

            //按文件名称升序排列
            FileInfo[] fileInfos = directoryInfo.GetFiles(searchPattern, searchOption).OrderBy(p => p.Name).ToArray();

            string strContent = "";

            for (int i = 0; i < fileInfos.Length; i++)
            {
                StreamReader sr = new StreamReader(fileInfos[i].OpenRead(), Encoding.Default);

                strContent = sr.ReadToEnd();

                if (strContent.Contains(strKeyword))
                {
                    strResult += fileInfos[i].FullName + "|";
                }

                sr.Close();
                sr.Dispose();

                strContent = "";
            }

            Array.Clear(fileInfos, 0, fileInfos.Length);
            return strResult;

        }
开发者ID:Paulyoufu,项目名称:elijah_window,代码行数:33,代码来源:FileHelper.cs


示例6: LoadImages

        public static List<ImageDescriptor> LoadImages(Uri uri, SearchOption searchOption)
        {

            var folderPath = uri.OriginalString;

            var fullNames = new string[] { };

            if (!folderPath.Equals(string.Empty))
                fullNames = Directory.GetFiles(folderPath, "*.*", searchOption);

            var list = new List<ImageDescriptor>();

            for (var i = 0; i < fullNames.Length; i++)
            {
                var filePath = fullNames[i];

                var imgInfo = DecodeBitmapImage(ref filePath, 128);

                if (imgInfo != null)
                    list.Add(imgInfo);
            }

            GC.Collect();

            return list;
        }
开发者ID:alexcmd,项目名称:CascadeTrainingTool,代码行数:26,代码来源:ImageManager.cs


示例7: FileSearchTemplate

 public FileSearchTemplate(DirectoryInfo directory, string pattern, SearchOption option)
     : this()
 {
     Pattern = pattern;
     Directory = directory;
     SearchOption = option;
 }
开发者ID:andyhebear,项目名称:BitsUpdater,代码行数:7,代码来源:FileSearchTemplate.cs


示例8: SearchData

        /// <summary>
        /// Initializes a new instance of the <see cref="SearchData"/> class.
        /// </summary>
        /// <param name="fullPath">The full path.</param>
        /// <param name="userPath">The user path.</param>
        /// <param name="searchOptions">The search options.</param>
        public SearchData(String fullPath, String userPath, SearchOption searchOptions)
        {
            Contract.Requires(fullPath != null);
            Contract.Requires(searchOptions == SearchOption.AllDirectories || searchOptions == SearchOption.TopDirectoryOnly);

            if( PathHelperMethods.IsDirectorySeparator(fullPath[fullPath.Length - 1]) )
            {
                this.fullPath = fullPath;
            }
            else
            {
                this.fullPath = fullPath + Path.DirectorySeparatorChar;
            }

            if( string.IsNullOrEmpty(userPath) || PathHelperMethods.IsDirectorySeparator(userPath[userPath.Length - 1]) )
            {
                this.userPath = userPath;
            }
            else
            {
                this.userPath = userPath + Path.DirectorySeparatorChar;
            }

            this.searchOptions = searchOptions;
        }
开发者ID:DavidMoore,项目名称:ipfilter,代码行数:31,代码来源:SearchData.cs


示例9: CopyTo

        public static void CopyTo(this DirectoryInfo sourceDirectory, string target, SearchOption option, string searchPattern)
        {
            if (target[target.Length - 1] != Path.DirectorySeparatorChar)
            {
                target += Path.DirectorySeparatorChar;
            }
            if (!Directory.Exists(target))
            {
                Directory.CreateDirectory(target);

                for (int i = 0; i < searchPattern.Length; i++)
                {
                    foreach (string file in Directory.GetFiles(sourceDirectory.FullName, searchPattern))
                    {
                        Console.WriteLine("Copying {0} to {1}", file, target + Path.GetFileName(file));
                        File.Copy(file, target + Path.GetFileName(file), true);
                    }
                }

                // Copy subdirectories (recursively)
                if (option == SearchOption.AllDirectories)
                {
                    foreach (string element in Directory.GetDirectories(sourceDirectory.FullName))
                    {
                        DirectoryInfo d = new DirectoryInfo(element);
                        CopyTo(d, target + Path.GetFileName(element), option, searchPattern);
                    }
                }
            }
        }
开发者ID:Quanto99,项目名称:ElementaryCSharp,代码行数:30,代码来源:Classes.cs


示例10: FindFiles

        /// <summary>
        /// Static method to find files in a specified path.
        /// </summary>
        /// <param name="path">Path to the folder where to look for files.</param>
        /// <param name="pattern">File name pPattern for the search.</param>
        /// <param name="so">Search option. TopDirectoryOnly to search only in the top folder or AllDirectories to search also in the sub-directories. The default is TopDirectoryOnly.</param>
        /// <returns></returns>
        public static FileInfo[] FindFiles(string path, string pattern, SearchOption so = SearchOption.TopDirectoryOnly)
        {
            DirectoryInfo di = new System.IO.DirectoryInfo(path);
             FileInfo[] fl = di.GetFiles(pattern, so);

             return fl;
        }
开发者ID:JauchOnGitHub,项目名称:jauch-toolbox,代码行数:14,代码来源:FilesTools.cs


示例11: EnumerateFiles

        /// <summary>
        /// Returns an enumerable collection of files in a specified path.
        /// </summary>
        /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param>
        /// <param name="searchOption">Specifiy depth with <see cref="SearchOption"/></param>
        /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param>
        /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns>
        public IEnumerable<QuickIOFileInfo> EnumerateFiles( String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
        {
            Contract.Requires( !String.IsNullOrWhiteSpace( pattern ) );
            Contract.Ensures(Contract.Result<IEnumerable<QuickIOFileInfo>>() != null);

            return QuickIODirectory.EnumerateFiles( FullNameUnc, pattern, searchOption );
        }
开发者ID:Invisibility,项目名称:QuickIO,代码行数:14,代码来源:QuickIODirectoryInfo.Enumerations.cs


示例12: EnumerateFilePaths

        /// <summary>
        /// Returns an enumerable collection of file names in a specified path.
        /// </summary>
        /// <param name="pattern">Search pattern. Uses Win32 native filtering.</param>
        /// <param name="searchOption">Specifiy depth with <see cref="SearchOption"/></param>
        /// <param name="pathFormatReturn">Specifies the type of path to return.</param>
        /// <param name="enumerateOptions">Options</param>
        /// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by path.</returns>
        public IEnumerable<string> EnumerateFilePaths( String pattern = QuickIOPatterns.PathMatchAll, SearchOption searchOption = SearchOption.TopDirectoryOnly, QuickIOPathType pathFormatReturn = QuickIOPathType.Regular, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None )
        {
            Contract.Requires( !String.IsNullOrWhiteSpace( pattern ) );
            Contract.Ensures( Contract.Result<IEnumerable<string>>() != null );

            return QuickIODirectory.EnumerateFilePaths( FullNameUnc, pattern, searchOption, pathFormatReturn, enumerateOptions );
        }
开发者ID:Invisibility,项目名称:QuickIO,代码行数:15,代码来源:QuickIODirectoryInfo.Enumerations.cs


示例13: Search

        /// <summary>
        /// Returns the names of files in a specified directories that match the specified patterns.
        /// </summary>
        /// <param name="source">The directory to search.</param>
        /// <param name="fileExtensions">The comma separated list of file extensions. <example>cs,cshtml</example>. </param>
        /// <param name="searchStrings">The list of search strings (ignore case).</param>
        /// <param name="searchOption">The search options. Default value is AllDirectories.</param>
        /// <returns> The list of files that match the specified criteria. </returns>
        public static List<SearchMatch> Search(this DirectoryInfo source, string fileExtensions, IEnumerable<string> searchStrings, SearchOption searchOption = SearchOption.AllDirectories)
        {
            var fileExtensionsList = fileExtensions.Split(',').Select(fileExtension => string.Format(@"*.{0}", fileExtension)).ToList();

            var filesToSearch = from searchPattern in fileExtensionsList
                                from files in Directory.GetFiles(source.FullName, searchPattern, searchOption)
                                select files;

            var matches = new List<SearchMatch>();

            foreach (var file in filesToSearch)
            {
                var lineNumber = 1;
                var lines = File.ReadAllLines(file);
                foreach (var line in lines)
                {
                    lineNumber++;
                    matches.AddRange(from searchString in searchStrings
                                     where line.Contains(searchString, StringComparison.OrdinalIgnoreCase)
                                     select new SearchMatch(file, lineNumber, line.Trim()));
                }
            }

            return matches;
        }
开发者ID:modulexcite,项目名称:CustomActivities,代码行数:33,代码来源:DirectoryInfoExtensions.cs


示例14: FindDatasets

        /// <summary>
        ///     Finds a list of input files within the folder provided.
        /// </summary>
        /// <param name="folderPath"></param>
        /// <returns></returns>
        public static List<InputFile> FindDatasets(string folderPath, List<string> extensions, SearchOption options)
        {
            var datasetList = new List<InputFile>();
            var candidates = new List<string>();

            foreach (var extension in extensions)
            {
                var paths = Directory.GetFiles(folderPath, "*" + extension, options);
                candidates.AddRange(paths);
            }

            foreach (var path in candidates)
            {
                var type = DatasetInformation.GetInputFileType(path);

                if (type == InputFileType.NotRecognized)
                {
                    continue;
                }

                var file = new InputFile();
                file.Path = path;
                file.FileType = type;

                datasetList.Add(file);
            }

            return datasetList;
        }
开发者ID:msdna,项目名称:MultiAlign,代码行数:34,代码来源:DatasetSearcher.cs


示例15: GetFiles

        /// <summary>
        /// Gets information ( array of <see cref="FileInfo"/> objects ), found by files <paramref name="mask"/> according to provided <see cref="SearchOption"/>.
        /// </summary>
        /// <param name="directory">Directory to search files in.</param>
        /// <param name="mask">Search pattern.</param>
        /// <param name="searchHow">Search option.</param>
        /// <returns>Array of <see cref="FileInfo"/> objects, containing information about files, that has been found.</returns>
        /// <exception cref="DirectoryNotFoundException" />
        public static FileInfo[] GetFiles( string directory, string mask, SearchOption searchHow )
        {
            if ( Directory.Exists(directory) )
                return new DirectoryInfo(directory).GetFiles(mask, searchHow);

            throw new DirectoryNotFoundException(String.Format("Directory '{0}' can't be found.", directory));
        }
开发者ID:Hefester,项目名称:l2c-devsadmin,代码行数:15,代码来源:L2FileReader.cs


示例16: findFilesFromPath

        public string[] findFilesFromPath(string path, string fileNameParam, SearchOption searchOp)
        {
            string[] filenames = null;
            filenames = Directory.GetFiles(@path, "*" + fileNameParam + "*", searchOp);

            return filenames;
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:7,代码来源:SearchComponentClass.cs


示例17: RequestURL

        internal override Uri RequestURL(SearchOption option)
        {
            StringBuilder sbQuery = new StringBuilder();

            sbQuery.Append(this.SearchURL);
            if (this.SearchURL.IndexOf('?') < 0)
                sbQuery.Append('?');
            else
                sbQuery.Append('&');

            if (!String.IsNullOrEmpty(option.Tags))
                sbQuery.AppendFormat("{0}={1}&", TagsName, Uri.EscapeUriString(option.Tags));

            if (option.Page != null)
                sbQuery.AppendFormat("{0}={1}&", PageName, option.Page.Value);

            if (option.Limit != null)
                sbQuery.AppendFormat("{0}={1}&", LimitName, option.Limit.Value);

            if (sbQuery[sbQuery.Length - 1] == '&')
                sbQuery.Remove(sbQuery.Length - 1, 1);

            if (sbQuery[sbQuery.Length - 1] == '?')
                sbQuery.Remove(sbQuery.Length - 1, 1);

            return new Uri(sbQuery.ToString());
        }
开发者ID:RyuaNerin,项目名称:ImageAPIs,代码行数:27,代码来源:SearchBooru.cs


示例18: GetFilesRelativeToRoot

        internal static IEnumerable<string> GetFilesRelativeToRoot(string root, string path, string filter = null, SearchOption searchOption = SearchOption.TopDirectoryOnly)
        {
            path = EnsureTrailingSlash(Path.Combine(root, path));
            if (String.IsNullOrEmpty(filter))
            {
                filter = "*.*";
            }
            try
            {
                if (!Directory.Exists(path))
                {
                    return Enumerable.Empty<string>();
                }
                return Directory.EnumerateFiles(path, filter, searchOption)
                    .Select(f => GetRelativePath(root, f));
            }
            catch (UnauthorizedAccessException)
            {
            }
            catch (DirectoryNotFoundException)
            {
            }

            return Enumerable.Empty<string>();
        }
开发者ID:eerhardt,项目名称:NuGet3,代码行数:25,代码来源:FileSystemUtility.cs


示例19: GetAllInputFiles

        static List<MyFileInfo> GetAllInputFiles(List<string> inputFiles, SearchOption searchOption)
        {
            List<MyFileInfo> result = new List<MyFileInfo>();
            foreach (var inputFile in inputFiles)
            {
                if (Path.HasExtension(inputFile))
                {
                    string dir = Path.GetDirectoryName(inputFile);
                    string ext = Path.GetFileName(inputFile);
                    var files = Directory.EnumerateFiles(dir, ext, searchOption);
                    foreach (var file in files)
                    {
                        result.Add(new MyFileInfo() { Info = new FileInfo(file), Root = new DirectoryInfo(Path.GetDirectoryName(inputFile)) });
                    }

                }
                else
                {
                    //is path
                    var files = Directory.EnumerateFiles(inputFile, "*.*", searchOption);
                    foreach (var file in files)
                    {
                        result.Add(new MyFileInfo() { Info = new FileInfo(file), Root = new DirectoryInfo(Path.GetDirectoryName(inputFile)) });
                    }
                }
            }

            return result;
        }
开发者ID:whztt07,项目名称:Medusa,代码行数:29,代码来源:Program.cs


示例20: FileFilterPipe

 /// <summary>
 /// Scans the given directories for files matching the given filters.
 /// </summary>
 /// <param name="IEnumerator">An enumerator of directories.</param>
 /// <param name="SearchPattern">A simple search pattern like "*.jpg".</param>
 /// <param name="SearchOption">Include or do not include subdirectories.</param>
 /// <param name="FileFilter">A delegate for filtering the found files.</param>
 /// <returns>An enumeration of file infos.</returns>
 public static IEnumerable<FileInfo> FileFilterPipe(this IEnumerator<String> IEnumerator,
                                                         String              SearchPattern = "*",
                                                         SearchOption        SearchOption  = SearchOption.TopDirectoryOnly,
                                                         FileFilter          FileFilter    = null)
 {
     return new FileFilterPipe(SearchPattern, SearchOption, FileFilter, null, IEnumerator);
 }
开发者ID:subbuballa,项目名称:Styx,代码行数:15,代码来源:IOPipeExtensions.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SearchOptions类代码示例发布时间:2022-05-24
下一篇:
C# SearchModel类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap