Exemplo n.º 1
0
        /// <summary>
        /// Gets <see cref="FileData"/> 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.</param>
        /// <param name="searchOption">The options for the search</param>
        /// <returns>An object that implements <see cref="IEnumerable{FileData}"/> and
        /// allows you to enumerate the files in the given directory.</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 FileData[] GetFiles(string path, string searchPattern, SearchOption searchOption)
        {
            IEnumerable <FileData> e    = FastDirectoryEnumerator.EnumerateFiles(path, searchPattern, searchOption);
            List <FileData>        list = new List <FileData>(e);

            FileData[] retval = new FileData[list.Count];
            list.CopyTo(retval);

            return(retval);
        }
Exemplo n.º 2
0
        protected override void Execute()
        {
            List <DirectoryInfo> ToSearch = new List <DirectoryInfo>();

            // Add directory to queue
            try
            {
                ToSearch.Add(new DirectoryInfo(_Directory));
            }
            catch (DirectoryNotFoundException dnf)
            {
                RaiseLogMessage("HANDLED DIRECTORYNOTFOUNDEXCEPTION while trying to read directory '" + _Directory + "': " + dnf.Message);
            }
            catch (Exception e)
            {
                RaiseLogError("UNHANDLED EXCEPTION while trying to read directory '" + _Directory + "': " + e.Message);
            }

            while (ToSearch.Count > 0)
            {
                DirectoryInfo DI = ToSearch[0];
                ToSearch.RemoveAt(0);
                Directories.Add(Regex.Replace(DI.FullName, _ReplaceInKey, "", RegexOptions.IgnoreCase), DI.FullName);

                RaiseDirectoryChanged(DI.FullName);

                if (_WantFiles)
                {
                    try
                    {
                        foreach (FileData FD in FastDirectoryEnumerator.EnumerateFiles(DI.FullName, "*.*", _Recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
                        {
                            Files.Add(Regex.Replace(FD.Path, _ReplaceInKey, "", RegexOptions.IgnoreCase), FD);
                        }
                    }
                    catch (DirectoryNotFoundException dnf)
                    {
                        RaiseLogMessage("HANDLED DIRECTORYNOTFOUNDEXCEPTION while trying to read files in directory '" + DI.FullName + "': " + dnf.Message);
                    }
                    catch (Exception e)
                    {
                        RaiseLogError("UNHANDLED EXCEPTION while trying to read files in directory '" + DI.FullName + "': " + e.Message);
                    }
                }

                if (_Recurse)
                {
                    try
                    {
                        ToSearch.AddRange(DI.GetDirectories());
                    }
                    catch (DirectoryNotFoundException dnf)
                    {
                        RaiseLogMessage("HANDLED DIRECTORYNOTFOUNDEXCEPTION while trying to read subdirectories in directory '" + DI.FullName + "': " + dnf.Message);
                    }
                    catch (Exception e)
                    {
                        RaiseLogError("UNHANDLED EXCEPTION while trying to read subdirectories in directory '" + DI.FullName + "': " + e.Message);
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Gets <see cref="FileData"/> 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.</param>
 /// <returns>An object that implements <see cref="IEnumerable{FileData}"/> and
 /// allows you to enumerate the files in the given directory.</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 IEnumerable <FileData> EnumerateFiles(string path, string searchPattern)
 {
     return(FastDirectoryEnumerator.EnumerateFiles(path, searchPattern, SearchOption.TopDirectoryOnly));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Gets <see cref="FileData"/> for all the files in a directory.
 /// </summary>
 /// <param name="path">The path to search.</param>
 /// <returns>An object that implements <see cref="IEnumerable{FileData}"/> and
 /// allows you to enumerate the files in the given directory.</returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="path"/> is a null reference (Nothing in VB)
 /// </exception>
 public static IEnumerable <FileData> EnumerateFiles(string path)
 {
     return(FastDirectoryEnumerator.EnumerateFiles(path, "*"));
 }