EditorTool3D/Assets/ZXL/Scripts/FileSystem/DirectoryInfo.cs

50 lines
1.4 KiB
C#
Raw Normal View History

2024-12-18 23:46:42 +08:00
using System.Collections.Generic;
namespace ZXLT.FileSystem
{
public sealed class DirectoryInfo : FileSystemInfo
{
List<DirectoryInfo> directories = new List<DirectoryInfo>();
List<FileInfo> files = new List<FileInfo>();
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();
}
}
}