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

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>
<PackageReference Include="NAudio" Version="2.2.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="SheEat\" />
</ItemGroup>
</Project>

View File

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

View File

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