From 4296abea79f92f33908794e182a5cb5e6e9dfa3f Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Tue, 25 Jul 2023 18:00:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=96=B9=E5=BC=8F=20=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E5=BD=93=E6=BC=AB=E7=94=BB=E5=90=8D=E5=8C=85=E5=90=AB=E5=85=A8?= =?UTF-8?q?=E8=A7=92=E6=95=B0=E5=AD=97=E6=97=B6=E5=87=BA=E9=94=99=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConsoleApp1/ConsoleApp1/Program.cs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/ConsoleApp1/ConsoleApp1/Program.cs b/ConsoleApp1/ConsoleApp1/Program.cs index 790446b..61b9580 100644 --- a/ConsoleApp1/ConsoleApp1/Program.cs +++ b/ConsoleApp1/ConsoleApp1/Program.cs @@ -14,7 +14,8 @@ namespace ConsoleApp1 static void Main(string[] args) { // 设置控制台的输出编码为UTF-8 - Console.OutputEncoding = Encoding.UTF8; + //Console.OutputEncoding = Encoding.UTF8; + Console.OutputEncoding = Encoding.GetEncoding(936); // 获取上级文件夹路径 Console.Write("请输入漫画所在的根路径:"); @@ -46,6 +47,9 @@ namespace ConsoleApp1 // 循环处理每个漫画文件夹 foreach (string comicFolder in comicFolders) { + // 输出开始处理提示信息 + Console.WriteLine($"开始处理漫画文件夹 {comicFolder}..."); + // 确保漫画文件夹中包含图像文件 string[] imageFiles = Directory.GetFiles(comicFolder, "*.*", SearchOption.AllDirectories) .Where(file => file.ToLower().EndsWith(".jpg") || file.ToLower().EndsWith(".png")) @@ -137,12 +141,16 @@ namespace ConsoleApp1 { public int Compare(string x, string y) { - // Define the regex pattern to match numbers in the strings + // Get the file names from the full file paths + string fileNameX = Path.GetFileName(x); + string fileNameY = Path.GetFileName(y); + + // Define the regex pattern to match numbers in the file names string pattern = @"(\d+)"; - // Get all the matches of numbers in the strings - MatchCollection matchesX = Regex.Matches(x, pattern); - MatchCollection matchesY = Regex.Matches(y, pattern); + // Get all the matches of numbers in the file names + MatchCollection matchesX = Regex.Matches(fileNameX, pattern); + MatchCollection matchesY = Regex.Matches(fileNameY, pattern); // Compare the matches one by one int matchCount = Math.Min(matchesX.Count, matchesY.Count); @@ -156,13 +164,13 @@ namespace ConsoleApp1 return numComparison; // Compare the non-numeric parts between the matched numbers - int nonNumericComparison = x.IndexOf(matchesX[i].Value) - y.IndexOf(matchesY[i].Value); + int nonNumericComparison = fileNameX.IndexOf(matchesX[i].Value) - fileNameY.IndexOf(matchesY[i].Value); if (nonNumericComparison != 0) return nonNumericComparison; } // If the numbers are the same up to this point, compare the remaining non-numeric parts - return x.CompareTo(y); + return fileNameX.CompareTo(fileNameY); } }