Ejemplo n.º 1
0
        /// <summary>
        /// Main method, which developer-user will call to get a list of
        ///  all of the files loaded into a sent in hashtable list
        /// </summary>
        /// <param name="p_TargetDir">The top-level directory you want to search</param>
        /// <param name="p_FilePattern">The file pattern you want to search, ex. *.*, frs*.old, msen.old</param>
        /// <param name="p_htDirs">Hashtable ref which will hold all of the directories searched</param>
        /// <param name="p_htFiles">Hashtable ref which will be a list of all the files found, which match
        /// the filepattern entered</param>
        /// <param name="p_SearchSubdirs">bool whether or not you want to search the subdirs</param>
        public static void CreateFileList(string p_TargetDir, string p_FilePattern,
                                          ref Hashtable p_htDirs, ref Hashtable p_htFiles, bool p_SearchSubdirs)
        {
            //CREATE A LIST OF FILES Which will be searched
            //basically get all of the files which match the file pattern
            //from the path the user entered p_TargetDir
            // if the user enters an empty string for the targetdir,
            // the application will get the currentdirectory (app.path) and continue
            string strCurrDir = string.Empty;

            if (p_TargetDir.Length != 0)
            {
                strCurrDir = p_TargetDir;
            }
            else
            {
                strCurrDir = Directory.GetCurrentDirectory();
            }

            try
            {
                // you could get an error when the user enters a bad path
                string[] files = Directory.GetFiles(strCurrDir, p_FilePattern);
                string[] Dirs  = Directory.GetDirectories(strCurrDir);
                int      DirCount;
                int      FileCount;
                // add all subdirectories
                for (DirCount = 0; DirCount < Dirs.Length; DirCount++)
                {
                    p_htDirs.Add(Dirs[DirCount], Dirs[DirCount]);
                }
                // add all files
                for (FileCount = 0; FileCount < files.Length; FileCount++)
                {
                    p_htFiles.Add(files[FileCount], files[FileCount]);
                }

                if (p_SearchSubdirs)
                {
                    // iterate through all of the directories in the current directory
                    System.Collections.IDictionaryEnumerator DirectoryEnum;
                    while (p_htDirs.Count > 0)
                    {
                        DirectoryEnum = p_htDirs.GetEnumerator();
                        DirectoryEnum.MoveNext();
                        // Get all the subdirs of this directory and add them to the directory hashtable
                        IterateDirectories(
                            DirectoryEnum.Key.ToString(),
                            p_FilePattern,
                            ref p_htDirs,
                            ref p_htFiles);
                    }
                }
            }
            catch (Exception OpenDirEx)
            {
            }
        }
Ejemplo n.º 2
0
        public static void CreateFileList(string p_TargetDir, string [] p_FilePattern,
                                          ref Hashtable p_htDirs, ref Hashtable p_htFiles, bool p_SearchSubdirs)
        {
            //CREATE A LIST OF FILES Which will be searched
            //basically get all of the files which match the file pattern
            //from the path the user entered p_TargetDir
            // if the user enters an empty string for the targetdir,
            // the application will get the currentdirectory (app.path) and continue
            string strCurrDir;

            if (p_TargetDir.Length != 0)
            {
                strCurrDir = p_TargetDir;
            }
            else
            {
                strCurrDir = Directory.GetCurrentDirectory();
            }
            try
            {
                string[]  files    = null;
                ArrayList FileList = new ArrayList();
                // you could get an error when the user enters a bad path
                foreach (string strPattern in p_FilePattern)
                {
                    files = Directory.GetFiles(p_TargetDir, strPattern);
                    foreach (string filename in files)
                    {
                        FileList.Add(filename);
                    }
                }
                string [] Dirs = Directory.GetDirectories(strCurrDir);
                int       DirCount;
                int       FileCount;
                // add all subdirectories
                for (DirCount = 0; DirCount < Dirs.Length; DirCount++)
                {
                    p_htDirs.Add(Dirs[DirCount], Dirs[DirCount]);

                    // RAD 12/01/04 Console.WriteLine(hsDir[Dirs[DirCount]]);
                }
                // add all files
                for (FileCount = 0; FileCount < FileList.Count; FileCount++)
                {
                    p_htFiles.Add(FileList[FileCount], FileList[FileCount]);
                }

                if (p_SearchSubdirs)
                {
                    // iterate through all of the directories in the current directory
                    //TODO: rename the enumerators so they make more sense
                    System.Collections.IDictionaryEnumerator DirectoryEnum;
                    while (p_htDirs.Count > 0)
                    {
                        DirectoryEnum = p_htDirs.GetEnumerator();
                        DirectoryEnum.MoveNext();
                        // Get all the subdirs of this directory and add them to the directory hashtable
                        IterateDirectories(DirectoryEnum.Key.ToString(), p_FilePattern, ref p_htDirs, ref p_htFiles);
                    }
                }
            }
            catch             //(Exception OpenDirEx)
            {
                //Console.WriteLine(OpenDirEx.Message);
            }
        }