From 66f4c5ffaf5d490df5f015263843f1d474e7687c Mon Sep 17 00:00:00 2001
From: muqing <1966944300@qq.com>
Date: Wed, 15 Jan 2025 00:42:13 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E9=A1=B9=E7=9B=AE=E6=96=87?=
=?UTF-8?q?=E4=BB=B6=EF=BC=8C=E7=A7=BB=E9=99=A4=E4=B8=8D=E5=BF=85=E8=A6=81?=
=?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6=E5=A4=B9=E5=BC=95=E7=94=A8=EF=BC=9B?=
=?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8E=A7=E5=88=B6=E5=8F=B0=E8=BE=93=E5=87=BA?=
=?UTF-8?q?=EF=BC=8C=E8=B0=83=E6=95=B4=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?=
=?UTF-8?q?=E5=92=8C=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Debug.csproj | 5 -----
Program.cs | 1 -
SearchFile.cs | 34 +++++++++++++++++++++++-----------
3 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/Debug.csproj b/Debug.csproj
index 4392967..7f65e79 100644
--- a/Debug.csproj
+++ b/Debug.csproj
@@ -10,9 +10,4 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/Program.cs b/Program.cs
index 173061f..efb08ab 100644
--- a/Program.cs
+++ b/Program.cs
@@ -14,7 +14,6 @@ public class Program
Console.Title = "Tools";//设置窗口标题
// 设置控制台输出编码,以支持复杂字符
Console.OutputEncoding = Encoding.UTF8;
- Console.Clear();
Console.CursorVisible = false;
// new MusicFrom();
_ = new Program();
diff --git a/SearchFile.cs b/SearchFile.cs
index 2e68645..2995efc 100644
--- a/SearchFile.cs
+++ b/SearchFile.cs
@@ -3,6 +3,7 @@ using Debug;
///
/// 文件夹文件搜索引擎操作
///
+namespace Debug;
public class Mod
{
private static DateTime time;
@@ -13,11 +14,16 @@ public class Mod
{
Console.WriteLine("结束" + (DateTime.Now - time).TotalMilliseconds + "ms");
}
+ ///
+ /// 开始时间
+ ///
private static void StartTime()
{
time = DateTime.Now;
}
+
+ // 是否过滤隐藏文件夹
private readonly bool Isdot = true;
//过滤系统
private readonly List 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 ? "文件" : "文件夹")}");
}
}
}
\ No newline at end of file