mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-03-03 15:30:27 +00:00
tree
This commit is contained in:
@@ -149,6 +149,79 @@ namespace CMLeonOS
|
|||||||
return fileList;
|
return fileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<string> GetDirectoryList(string path = ".")
|
||||||
|
{
|
||||||
|
string fullPath = GetFullPath(path);
|
||||||
|
List<string> dirList = new List<string>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Directory.Exists(fullPath))
|
||||||
|
{
|
||||||
|
var dirs = Directory.GetDirectories(fullPath);
|
||||||
|
foreach (var dir in dirs)
|
||||||
|
{
|
||||||
|
string dirName = Path.GetFileName(dir);
|
||||||
|
dirList.Add(dirName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error getting directory list: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return dirList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<string> GetFullPathFileList(string path = ".")
|
||||||
|
{
|
||||||
|
string fullPath = GetFullPath(path);
|
||||||
|
List<string> fileList = new List<string>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Directory.Exists(fullPath))
|
||||||
|
{
|
||||||
|
var files = Directory.GetFiles(fullPath);
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
fileList.Add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error getting file list: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<string> GetFullPathDirectoryList(string path = ".")
|
||||||
|
{
|
||||||
|
string fullPath = GetFullPath(path);
|
||||||
|
List<string> dirList = new List<string>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Directory.Exists(fullPath))
|
||||||
|
{
|
||||||
|
var dirs = Directory.GetDirectories(fullPath);
|
||||||
|
foreach (var dir in dirs)
|
||||||
|
{
|
||||||
|
dirList.Add(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error getting directory list: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return dirList;
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateFile(string path, string content = "")
|
public void CreateFile(string path, string content = "")
|
||||||
{
|
{
|
||||||
string fullPath = GetFullPath(path);
|
string fullPath = GetFullPath(path);
|
||||||
|
|||||||
2
Nano.cs
2
Nano.cs
@@ -661,7 +661,7 @@ namespace CMLeonOS
|
|||||||
Console.BackgroundColor = ConsoleColor.White;
|
Console.BackgroundColor = ConsoleColor.White;
|
||||||
Console.ForegroundColor = ConsoleColor.Black;
|
Console.ForegroundColor = ConsoleColor.Black;
|
||||||
Console.SetCursorPosition(0, 0);
|
Console.SetCursorPosition(0, 0);
|
||||||
string text = " Nano Editor 1.2";
|
string text = " CMLeonOS Nano Editor";
|
||||||
Console.WriteLine(text + new string(' ', consoleWidth - text.Length));
|
Console.WriteLine(text + new string(' ', consoleWidth - text.Length));
|
||||||
|
|
||||||
string displayName = path == null ? "New File" : System.IO.Path.GetFileName(path);
|
string displayName = path == null ? "New File" : System.IO.Path.GetFileName(path);
|
||||||
|
|||||||
77
Shell.cs
77
Shell.cs
@@ -434,6 +434,9 @@ namespace CMLeonOS
|
|||||||
case "find":
|
case "find":
|
||||||
FindFile(args);
|
FindFile(args);
|
||||||
break;
|
break;
|
||||||
|
case "tree":
|
||||||
|
ShowTree(args);
|
||||||
|
break;
|
||||||
case "getdisk":
|
case "getdisk":
|
||||||
GetDiskInfo();
|
GetDiskInfo();
|
||||||
break;
|
break;
|
||||||
@@ -1324,6 +1327,80 @@ namespace CMLeonOS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ShowTree(string args)
|
||||||
|
{
|
||||||
|
string startPath = string.IsNullOrEmpty(args) ? "." : args;
|
||||||
|
string fullPath = fileSystem.GetFullPath(startPath);
|
||||||
|
|
||||||
|
if (!System.IO.Directory.Exists(fullPath))
|
||||||
|
{
|
||||||
|
ShowError($"Directory not found: {startPath}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine(fullPath);
|
||||||
|
PrintDirectoryTree(fullPath, "", true);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ShowError($"Error displaying tree: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrintDirectoryTree(string path, string prefix, bool isLast)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var dirs = fileSystem.GetFullPathDirectoryList(path);
|
||||||
|
var files = fileSystem.GetFullPathFileList(path);
|
||||||
|
|
||||||
|
int totalItems = dirs.Count + files.Count;
|
||||||
|
int current = 0;
|
||||||
|
|
||||||
|
foreach (var dir in dirs)
|
||||||
|
{
|
||||||
|
current++;
|
||||||
|
bool isLastItem = current == totalItems;
|
||||||
|
string connector = isLastItem ? "+-- " : "|-- ";
|
||||||
|
string newPrefix = prefix + (isLastItem ? " " : "| ");
|
||||||
|
|
||||||
|
string dirName = System.IO.Path.GetFileName(dir);
|
||||||
|
Console.WriteLine($"{prefix}{connector}{dirName}/");
|
||||||
|
|
||||||
|
PrintDirectoryTree(dir, newPrefix, isLastItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
current++;
|
||||||
|
bool isLastItem = current == totalItems;
|
||||||
|
string connector = isLastItem ? "+-- " : "|-- ";
|
||||||
|
|
||||||
|
string fileName = System.IO.Path.GetFileName(file);
|
||||||
|
Console.WriteLine($"{prefix}{connector}{fileName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (System.IO.DirectoryNotFoundException)
|
||||||
|
{
|
||||||
|
ShowError($"Directory not found: {path}");
|
||||||
|
}
|
||||||
|
// catch (System.IO.UnauthorizedAccessException)
|
||||||
|
// {
|
||||||
|
// ShowError($"Access denied to directory: {path}");
|
||||||
|
// }
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string errorMsg = ex.Message;
|
||||||
|
if (string.IsNullOrEmpty(errorMsg))
|
||||||
|
{
|
||||||
|
errorMsg = $"Error type: {ex.GetType().Name}";
|
||||||
|
}
|
||||||
|
ShowError($"Error reading directory {path}: {errorMsg}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void GetDiskInfo()
|
private void GetDiskInfo()
|
||||||
{
|
{
|
||||||
Console.WriteLine("====================================");
|
Console.WriteLine("====================================");
|
||||||
|
|||||||
Reference in New Issue
Block a user