清理项目文件,移除不必要的文件夹引用;优化控制台输出,调整提示信息和异常处理

This commit is contained in:
muqing 2025-01-15 00:42:13 +08:00
parent 2188920f58
commit 66f4c5ffaf
3 changed files with 23 additions and 17 deletions

View File

@ -10,9 +10,4 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="NAudio" Version="2.2.1" /> <PackageReference Include="NAudio" Version="2.2.1" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="SheEat\" />
</ItemGroup>
</Project> </Project>

View File

@ -14,7 +14,6 @@ public class Program
Console.Title = "Tools";//设置窗口标题 Console.Title = "Tools";//设置窗口标题
// 设置控制台输出编码,以支持复杂字符 // 设置控制台输出编码,以支持复杂字符
Console.OutputEncoding = Encoding.UTF8; Console.OutputEncoding = Encoding.UTF8;
Console.Clear();
Console.CursorVisible = false; Console.CursorVisible = false;
// new MusicFrom(); // new MusicFrom();
_ = new Program(); _ = new Program();

View File

@ -3,6 +3,7 @@ using Debug;
/// <summary> /// <summary>
/// 文件夹文件搜索引擎操作 /// 文件夹文件搜索引擎操作
/// </summary> /// </summary>
namespace Debug;
public class Mod public class Mod
{ {
private static DateTime time; private static DateTime time;
@ -13,11 +14,16 @@ public class Mod
{ {
Console.WriteLine("结束" + (DateTime.Now - time).TotalMilliseconds + "ms"); Console.WriteLine("结束" + (DateTime.Now - time).TotalMilliseconds + "ms");
} }
/// <summary>
/// 开始时间
/// </summary>
private static void StartTime() private static void StartTime()
{ {
time = DateTime.Now; time = DateTime.Now;
} }
// 是否过滤隐藏文件夹
private readonly bool Isdot = true; private readonly bool Isdot = true;
//过滤系统 //过滤系统
private readonly List<string> ExcludeFile = [ private readonly List<string> ExcludeFile = [
@ -52,17 +58,16 @@ public class Mod
{ {
isFile = false; isFile = false;
} }
Console.Write($"请输入{(isFile ? "" : "")}"); Console.Write($"请输入{(isFile ? "" : "")}名称");
var v = Console.ReadLine(); var v = Console.ReadLine();
if (v == null || string.IsNullOrEmpty(v)) if (v == null || string.IsNullOrEmpty(v))
{ {
Console.Write("输入错误"); Console.Write("输入错误");
_ = new Program(); _ = new Mod();
return; return;
} }
fileName = v; fileName = v;
Console.Clear(); Console.Clear();
Init(); Init();
} }
private bool isFile = true;//是否搜索的是文件 private bool isFile = true;//是否搜索的是文件
@ -71,22 +76,24 @@ public class Mod
private void Init() private void Init()
{ {
//开始计时
StartTime(); StartTime();
//获取所有驱动器
var allDrives = DriveInfo.GetDrives(); var allDrives = DriveInfo.GetDrives();
foreach (var d in allDrives) foreach (var d in allDrives)
{ {
Console.WriteLine(); Console.Clear();
//判断是否可读
if (d.IsReady == true) if (d.IsReady == true)
{ {
var name = d.Name; var name = d.Name;
// if (name.Contains("C:\\"))//排除系统盘 if (name.Contains("C:\\"))//排除系统盘
// { {
// continue; continue;
// } }
// Console.WriteLine(name);
FileSearch(name); FileSearch(name);
} }
//结束计时
EndTime(); EndTime();
Yes(); Yes();
} }
@ -95,9 +102,11 @@ public class Mod
{ {
try try
{ {
//获取文件夹
DirectoryInfo dirInfo = new(path); DirectoryInfo dirInfo = new(path);
foreach (var directory in dirInfo.EnumerateDirectories()) foreach (var directory in dirInfo.EnumerateDirectories())
{ {
Console.Clear();
Console.WriteLine("正在搜索:" + directory); Console.WriteLine("正在搜索:" + directory);
//判断是否有访问权限 //判断是否有访问权限
if (!directory.Exists) if (!directory.Exists)
@ -123,10 +132,12 @@ public class Mod
} }
FileSearch(directory.FullName); FileSearch(directory.FullName);
} }
//处理文件
if (isFile) if (isFile)
{ {
foreach (var file in dirInfo.EnumerateFiles()) foreach (var file in dirInfo.EnumerateFiles())
{ {
Console.Clear();
Console.WriteLine("正在搜索:" + file.FullName); Console.WriteLine("正在搜索:" + file.FullName);
// 处理文件 // 处理文件
if (file.Name.Equals(fileName) && file.Exists) if (file.Name.Equals(fileName) && file.Exists)
@ -140,6 +151,7 @@ public class Mod
} }
catch (Exception ex) catch (Exception ex)
{ {
//处理异常
Console.WriteLine($"Error accessing directory '{path}': {ex.Message}"); Console.WriteLine($"Error accessing directory '{path}': {ex.Message}");
} }
} }
@ -151,7 +163,7 @@ public class Mod
} }
else else
{ {
Console.Write($"未找到 {(isFile ? "" : "")}"); Console.Write($"未找到 {fileName}:{(isFile ? "" : "")}");
} }
} }
} }