/// <summary> Insert a new page into this collection, based on the file name </summary>
        /// <param name="NewPageFile"></param>
        /// <returns></returns>
        internal int Insert(Builder_Page_File NewPageFile)
        {
            if (List.Count == 0)
            {
                return List.Add(NewPageFile);
            }

            if (NewPageFile.CompareTo(this[0]) <= 0)
            {
                List.Insert(0, NewPageFile);
                return 0;
            }

            if (NewPageFile.CompareTo(this[List.Count - 1]) >= 0)
            {
                return List.Add(NewPageFile);
            }

            return Recursive_Sort_Insert(NewPageFile, 0, List.Count - 1);
        }
        private static void get_files_from_current_directory(Builder_Page_File_Collection FileList, List<string> FileFilters, string SourceDirectory, string RelativeDirectory, bool RecursivelyIncludeSubfolders)
        {
            // Get the files in this directory by using file filters ( a single filter may find the same
            // file in this directory twice, so special code is added for this case )
            List<string> files_in_this_dir = new List<string>();
            foreach (string thisFilter in FileFilters)
            {
                string[] thisFilterFiles = Directory.GetFiles(SourceDirectory, thisFilter);
                foreach (string thisFilterFile in thisFilterFiles)
                {
                    if (!files_in_this_dir.Contains(thisFilterFile))
                        files_in_this_dir.Add(thisFilterFile);
                }
            }

            // All found files should be added to the builder page file collection
            foreach (string thisFile in files_in_this_dir)
            {
                // Exclude the archival files
                if ((thisFile.ToUpper().IndexOf("_ARCHIVE.") < 0) && (thisFile.ToUpper().IndexOf(".QC.JPG") < 0))
                {
                    // Create the new page_file object
                    Builder_Page_File newFile = new Builder_Page_File(thisFile, RelativeDirectory, true);

                    // Add into the page file collection, sorting appropriately
                    FileList.Insert(newFile);
                }
            }

            // Check subdirectories
            if (RecursivelyIncludeSubfolders)
            {
                string[] subdirs = Directory.GetDirectories(SourceDirectory);
                foreach (string thisSubDir in subdirs)
                {
                    DirectoryInfo thisSubDirInfo = new DirectoryInfo(thisSubDir);
                    string dir_name = thisSubDirInfo.Name;
                    if (RelativeDirectory.Length == 0)
                        get_files_from_current_directory(FileList, FileFilters, thisSubDir, dir_name, true);
                    else
                        get_files_from_current_directory(FileList, FileFilters, thisSubDir, RelativeDirectory + "\\" + dir_name, true);
                }
            }
        }
        private static void recursively_add_all_METS_files(abstract_TreeNode RootNode,
                                                           List<SobekCM_File_Info> METSFiles, Builder_Page_File_Collection METSFileCollection,
                                                           Dictionary<SobekCM_File_Info, Page_TreeNode> FileToPage, Dictionary<Page_TreeNode, Division_TreeNode> PageToDiv,
                                                           List<string> FileFilters)
        {
            if (RootNode.Page)
            {
                Page_TreeNode pageNode = (Page_TreeNode) RootNode;
                foreach (SobekCM_File_Info thisFile in pageNode.Files)
                {
                    bool add_file = false;
                    if (FileFilters.Count == 0)
                    {
                        add_file = true;
                    }
                    else
                    {
                        foreach (string file_filter in FileFilters)
                        {
                            if (thisFile.System_Name.ToUpper().IndexOf(file_filter) > 0)
                            {
                                add_file = true;
                                break;
                            }
                        }
                    }

                    if (add_file)
                    {
                        METSFiles.Add(thisFile);
                        Builder_Page_File newPageFile = new Builder_Page_File(thisFile.System_Name, true);
                        newPageFile.METS_Page = pageNode;
                        newPageFile.METS_Division = PageToDiv[pageNode];
                        METSFileCollection.Insert(newPageFile);
                        FileToPage.Add(thisFile, pageNode);
                    }
                }
            }
            else
            {
                Division_TreeNode divNode = (Division_TreeNode) RootNode;
                foreach (abstract_TreeNode thisNode in divNode.Nodes)
                {
                    if (thisNode.Page)
                    {
                        try
                        {
                            if (!PageToDiv.ContainsKey((Page_TreeNode) thisNode))
                            {
                                PageToDiv.Add((Page_TreeNode) thisNode, divNode);
                            }
                        }
                        catch
                        {
                        }
                    }

                    recursively_add_all_METS_files(thisNode, METSFiles, METSFileCollection, FileToPage, PageToDiv, FileFilters);
                }
            }
        }
 /// <summary> Add a new Page_File to this collection. </summary>
 /// <param name="NewPageFile"> <see cref="Builder_Page_File"/> object for this new Page_File </param>
 internal void Add(Builder_Page_File NewPageFile)
 {
     // Add this constructed Page_File to the collection
     List.Add(NewPageFile);
 }
        internal int Recursive_Sort_Insert(Builder_Page_File NewPageFile, int Start, int End)
        {
            int startIndex = Start;
            int endIndex = End;
            int midIndex = (int) Math.Ceiling((double) (endIndex - startIndex)/2) + startIndex;
            if (endIndex - startIndex <= 1)
            {
                if (NewPageFile.CompareTo(this[startIndex]) <= 0)
                {
                    List.Insert(startIndex, NewPageFile);
                    return startIndex;
                }

                List.Insert(endIndex, NewPageFile);
                return endIndex;
            }

            if (NewPageFile.CompareTo(this[midIndex]) < 0)
                endIndex = midIndex;
            else
                startIndex = midIndex;

            return Recursive_Sort_Insert(NewPageFile, startIndex, endIndex);
        }