Example #1
0
        public static DirectoryDescriptor[] GetDirectoryDescriptors(string path, string pattern = null, bool recursive = false)
        {
            string realPath = PathExpress.ResolvePath(path);
            ICollection <DirectoryDescriptor> results = new List <DirectoryDescriptor>();

            string[] directoryPathArray = pattern == null?Directory.GetDirectories(realPath) : Directory.GetDirectories(realPath, pattern);

            foreach (string directoryPath in directoryPathArray)
            {
                DirectoryDescriptor directoryDescriptor = GetDirectoryDescriptor(directoryPath);
                results.Add(directoryDescriptor);
            }
            if (recursive)
            {
                string[] subDirectoryPaths = Directory.GetDirectories(realPath);
                foreach (string directoryPath in subDirectoryPaths)
                {
                    DirectoryDescriptor[] directoryDescriptors = GetDirectoryDescriptors(directoryPath, pattern, true);
                    foreach (DirectoryDescriptor directoryDescriptor in directoryDescriptors)
                    {
                        results.Add(directoryDescriptor);
                    }
                }
            }
            return(results.ToArray());
        }
Example #2
0
        public static DirectoryDescriptor GetDirectoryDescriptor(string path, bool includeProperty = false)
        {
            string realPath            = PathExpress.ResolvePath(path);
            string name                = Path.GetFileName(realPath);
            string parentPath          = Path.GetDirectoryName(realPath);
            DirectoryDescriptor result = new DirectoryDescriptor(name, null, parentPath);

            return(result);
        }