Broadm 发表于 2024-11-5 17:10 没事啊, 能帮到就行 C#写的, 源码如下: [C#] 纯文本查看 复制代码using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tools { class BookTableItem { public string id { get; set; } public string type { get; set; } public string name { get; set; } public string bookNum { get; set; } public string isbn { get; set; } public string imageUrl { get; set; } public string modifyTime { get; set; } public string createTime { get; set; } public string authorNames { get; set; } public override string ToString() { return $"{id}, {type}, {name}, {bookNum}, {isbn}, {modifyTime}, {createTime}, {authorNames}"; } } class Program { static void Main() { var exeDir = AppDomain.CurrentDomain.BaseDirectory; var bookTablePath = Path.Combine(exeDir, "书表.txt"); var invalidPathChars = Path.GetInvalidPathChars(); try { Console.WriteLine("开始读取书表..."); var bookTableItems = ReadBookTable(bookTablePath); Console.WriteLine("成功读取书表..."); var filenames = Directory.GetFiles(exeDir); foreach (var filename in filenames) { if (filename.IndexOf("书表", StringComparison.OrdinalIgnoreCase) != -1) { continue; } if (filename.IndexOf("Tools.exe", StringComparison.OrdinalIgnoreCase) != -1) { continue; } var nameWithExt = Path.GetFileName(filename); var pureName = Path.GetFileNameWithoutExtension(nameWithExt); var ext = nameWithExt.Replace(pureName, ""); if (int.TryParse(pureName, out var _)) { var item = bookTableItems.FirstOrDefault(a => a.bookNum == pureName); if (item != null) { var destPureName = $"{item.createTime.Substring(0, 4)}_{item.name}_{item.isbn}"; var destFileName = destPureName + ext; try { File.Move(filename, Path.Combine(exeDir, destFileName)); Console.WriteLine($"处理成功: {nameWithExt} => {destFileName}"); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.WriteLine($"处理失败: {nameWithExt} => {destFileName}"); Console.ResetColor(); } } } } Console.WriteLine("处理完毕..."); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); } private static List[B] ReadBookTable(string bookTablePath) { if (!File.Exists(bookTablePath)) { throw new Exception("未找到 书表.txt"); } string[] lines = File.ReadAllLines(bookTablePath); if (lines == null || lines.Length == 0) { throw new Exception("书表没有内容"); } var BookTableItems = new List[B](lines.Length); int lineNumber = 0; //id,type,name,bookNum,isbn,imageUrl,modifyTime,createTime,authorNames foreach (string line in lines) { lineNumber++; if (lineNumber == 1 || line.Contains(",,,") || line.Length