Esempio n. 1
0
        public static string[] SearchFullNames(string dir_path, List <string> extensions, bool recursive, bool include_dirs, bool relative_path)
        {
            DirectoryInfo root            = new DirectoryInfo(dir_path);
            List <string> items           = new List <string>();
            bool          index_all_files = false;

            //if (extensions.Contains(".*"))
            //    return SearchFullNames(dir_path, recursive, include_dirs, relative_path);
            if (extensions.Contains(".*"))
            {
                index_all_files = true;
            }
            try
            {
                foreach (FileInfo file in root.GetFiles())
                {
                    if (index_all_files || extensions.Contains(file.Extension.ToLower()))
                    {
                        items.Add(relative_path ?
                                  FileNameManipulator.RelativePath(file.FullName, Environment.CurrentDirectory)
                            : file.FullName);
                    }
                }
                if (include_dirs)
                {
                    foreach (DirectoryInfo dir in root.GetDirectories())
                    {
                        items.Add(relative_path ?
                                  FileNameManipulator.RelativePath(dir.FullName + "\\", Environment.CurrentDirectory)
                            : dir.FullName + "\\");
                    }
                }
                if (recursive)
                {
                    foreach (DirectoryInfo directory in root.GetDirectories())
                    {
                        items.AddRange(SearchFullNames(directory.FullName, extensions, recursive, include_dirs, relative_path));
                    }
                }
            }
            catch
            {
            }
            return(items.ToArray());
        }
Esempio n. 2
0
        public static string[] SearchFullNames(string dir_path, bool recursive, bool include_dirs, bool relative_path)
        {
            List <string> items = new List <string>();

            foreach (string file in Directory.GetFiles(dir_path, "*.*", (recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)))
            {
                items.Add(relative_path ?
                          FileNameManipulator.RelativePath(file, Environment.CurrentDirectory)
                    : file);
            }
            if (include_dirs)
            {
                foreach (string dir in Directory.GetDirectories(dir_path, "*", (recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)))
                {
                    items.Add(relative_path ?
                              FileNameManipulator.RelativePath(dir, Environment.CurrentDirectory)
                        : dir + "\\");
                }
            }
            return(items.ToArray());
        }