Example #1
0
        public static async Task <IEnumerable <FastFileInfo> > EnumerateFilesFastv2Async(string rootPath, string searchPattern, SearchOption searchOption)
        {
            var t = await Task.Run(() =>
            {
                return(FastFileInfo.EnumerateFiles(rootPath, searchPattern, searchOption));;
            });

            return(t);
        }
Example #2
0
        /// <summary>
        /// Gets <see cref="FastFileInfo"/> for all the files in a directory that match a specific filter.
        /// </summary>
        /// <param name="path">The path to search.</param>
        /// <param name="searchPattern">The search string to match against files in the path. Multiple can be specified separated by the pipe character.</param>
        /// <returns>An list of FastFileInfo objects that match the specified search pattern.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="path"/> is a null reference (Nothing in VB)
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="filter"/> is a null reference (Nothing in VB)
        /// </exception>
        public static IList <FastFileInfo> GetFiles(String path, String searchPattern = "*", SearchOption searchOption = SearchOption.TopDirectoryOnly)
        {
            List <FastFileInfo> list = new List <FastFileInfo>();

            String[]  arr = searchPattern.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            Hashtable ht  = (arr.Length > 1 ? new Hashtable() : null); // don't need to worry about case since it should be consistent

            foreach (String sp in arr)
            {
                String sp2 = sp.Trim();
                if (sp2.Length == 0)
                {
                    continue;
                }

                IEnumerable <FastFileInfo> e = EnumerateFiles(path, sp2, searchOption);
                if (ht == null)
                {
                    list.AddRange(e);
                }
                else
                {
                    var e2 = e.GetEnumerator();
                    if (ht.Count == 0)
                    {
                        while (e2.MoveNext())
                        {
                            FastFileInfo f = e2.Current;
                            list.Add(f);
                            ht[f.FullName] = f;
                        }
                    }
                    else
                    {
                        while (e2.MoveNext())
                        {
                            FastFileInfo f = e2.Current;
                            if (!ht.Contains(f.FullName))
                            {
                                list.Add(f);
                                ht[f.FullName] = f;
                            }
                        }
                    }
                }
            }

            return(list);
        }