using System.Collections.Generic; namespace ZXLT.FileSystem { public sealed class DirectoryInfo : FileSystemInfo { List directories = new List(); List files = new List(); public override bool Exists { get; } public override string Name => _name; public DirectoryInfo Parent { get { var directoryInfo = new DirectoryInfo(System.IO.Path.GetDirectoryName(FullPath)); return directoryInfo; } } public DirectoryInfo Root => new DirectoryInfo(System.IO.Path.GetPathRoot(this.FullPath)); public DirectoryInfo(string path) { this.Init(path, System.IO.Path.GetFullPath(path), isNormalized: true); FullPath = path; _name = path; } private void Init(string originalPath, string fullPath = null, string fileName = null, bool isNormalized = false) { if (fullPath == null) fullPath = originalPath; fullPath = isNormalized ? fullPath : System.IO.Path.GetFullPath(fullPath); this._name = fileName; this.FullPath = fullPath; } public DirectoryInfo[] GetDirectories() { return directories.ToArray(); } public FileInfo[] GetFiles() { return files.ToArray(); } } }