예제 #1
0
        /// <summary>
        /// Returns a list of all files found in the given folder.
        /// The search is recursive.
        /// </summary>
        /// <param name="rootpath">The folder to look in</param>
        /// <param name="callback">The function to call with the filenames</param>
        /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
        /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
        /// <param name="attributeReader">A function to call that obtains the attributes for an element, set to null to avoid reading attributes</param>
        /// <returns>A list of the full filenames</returns>
        public static void EnumerateFileSystemEntries(string rootpath, EnumerationCallbackDelegate callback, FileSystemInteraction folderList, FileSystemInteraction fileList, ExtractFileAttributes attributeReader)
        {
            if (!System.IO.Directory.Exists(rootpath))
                return;

            Queue<string> lst = new Queue<string>();
            lst.Enqueue(rootpath);

            while (lst.Count > 0)
            {
                string f = AppendDirSeparator(lst.Dequeue());
                try
                {
                    System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Directory : attributeReader(f);
                    if (!callback(rootpath, f, attr))
                        continue;

                    foreach (string s in folderList(f))
                        lst.Enqueue(s);
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception)
                {
                    callback(rootpath, f, ATTRIBUTE_ERROR | System.IO.FileAttributes.Directory);
                }

                try
                {
                    if (fileList != null)
                        foreach (string s in fileList(f))
                        {
                            try
                            {
                                System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Normal : attributeReader(s);
                                callback(rootpath, s, attr);
                            }
                            catch (System.Threading.ThreadAbortException)
                            {
                                throw;
                            }
                            catch (Exception)
                            {
                                callback(rootpath, s, ATTRIBUTE_ERROR);
                            }
                        }
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception)
                {
                    callback(rootpath, f, ATTRIBUTE_ERROR);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Returns a list of all files found in the given folder.
 /// The search is recursive.
 /// </summary>
 /// <param name="rootpath">The folder to look in</param>
 /// <param name="callback">The function to call with the filenames</param>
 /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
 /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
 /// <returns>A list of the full filenames</returns>
 public static void EnumerateFileSystemEntries(string rootpath, EnumerationCallbackDelegate callback, FileSystemInteraction folderList, FileSystemInteraction fileList)
 {
     EnumerateFileSystemEntries(rootpath, callback, folderList, fileList, null);
 }
예제 #3
0
 /// <summary>
 /// Returns a list of all files found in the given folder.
 /// The search is recursive.
 /// </summary>
 /// <param name="rootpath">The folder to look in</param>
 /// <param name="filter">An optional filter to apply to the filenames</param>
 /// <param name="callback">The function to call with the filenames</param>
 /// <returns>A list of the full filenames</returns>
 public static void EnumerateFileSystemEntries(string rootpath, EnumerationCallbackDelegate callback)
 {
     EnumerateFileSystemEntries(rootpath, callback, new FileSystemInteraction(System.IO.Directory.GetDirectories), new FileSystemInteraction(System.IO.Directory.GetFiles));
 }
예제 #4
0
        /// <summary>
        /// Returns a list of all files found in the given folder.
        /// The search is recursive.
        /// </summary>
        /// <param name="rootpath">The folder to look in</param>
        /// <param name="callback">The function to call with the filenames</param>
        /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
        /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
        /// <param name="attributeReader">A function to call that obtains the attributes for an element, set to null to avoid reading attributes</param>
        /// <returns>A list of the full filenames</returns>
        public static void EnumerateFileSystemEntries(string rootpath, EnumerationCallbackDelegate callback, FileSystemInteraction folderList, FileSystemInteraction fileList, ExtractFileAttributes attributeReader)
        {
            if (!System.IO.Directory.Exists(rootpath))
            {
                return;
            }

            Queue <string> lst = new Queue <string>();

            lst.Enqueue(rootpath);

            while (lst.Count > 0)
            {
                string f = AppendDirSeparator(lst.Dequeue());
                try
                {
                    System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Directory : attributeReader(f);
                    if (!callback(rootpath, f, attr))
                    {
                        continue;
                    }

                    foreach (string s in folderList(f))
                    {
                        lst.Enqueue(s);
                    }
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception)
                {
                    callback(rootpath, f, ATTRIBUTE_ERROR | System.IO.FileAttributes.Directory);
                }

                try
                {
                    if (fileList != null)
                    {
                        foreach (string s in fileList(f))
                        {
                            try
                            {
                                System.IO.FileAttributes attr = attributeReader == null ? System.IO.FileAttributes.Normal : attributeReader(s);
                                callback(rootpath, s, attr);
                            }
                            catch (System.Threading.ThreadAbortException)
                            {
                                throw;
                            }
                            catch (Exception)
                            {
                                callback(rootpath, s, ATTRIBUTE_ERROR);
                            }
                        }
                    }
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception)
                {
                    callback(rootpath, f, ATTRIBUTE_ERROR);
                }
            }
        }
예제 #5
0
 /// <summary>
 /// Returns a list of all files found in the given folder.
 /// The search is recursive.
 /// </summary>
 /// <param name="rootpath">The folder to look in</param>
 /// <param name="callback">The function to call with the filenames</param>
 /// <param name="folderList">A function to call that lists all folders in the supplied folder</param>
 /// <param name="fileList">A function to call that lists all files in the supplied folder</param>
 /// <returns>A list of the full filenames</returns>
 public static void EnumerateFileSystemEntries(string rootpath, EnumerationCallbackDelegate callback, FileSystemInteraction folderList, FileSystemInteraction fileList)
 {
     EnumerateFileSystemEntries(rootpath, callback, folderList, fileList, null);
 }
예제 #6
0
 /// <summary>
 /// Returns a list of all files found in the given folder.
 /// The search is recursive.
 /// </summary>
 /// <param name="rootpath">The folder to look in</param>
 /// <param name="filter">An optional filter to apply to the filenames</param>
 /// <param name="callback">The function to call with the filenames</param>
 /// <returns>A list of the full filenames</returns>
 public static void EnumerateFileSystemEntries(string rootpath, EnumerationCallbackDelegate callback)
 {
     EnumerateFileSystemEntries(rootpath, callback, new FileSystemInteraction(System.IO.Directory.GetDirectories), new FileSystemInteraction(System.IO.Directory.GetFiles));
 }