From 358cc33f3a974f35ce73e4bbf261a43176e4f6ef Mon Sep 17 00:00:00 2001 From: limil Date: Sat, 1 Nov 2025 11:55:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BangumiRenamer.csproj | 1 + Src/Tools/FolderCloner.cs | 68 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 Src/Tools/FolderCloner.cs diff --git a/BangumiRenamer.csproj b/BangumiRenamer.csproj index 9733700..56073f6 100644 --- a/BangumiRenamer.csproj +++ b/BangumiRenamer.csproj @@ -16,6 +16,7 @@ + diff --git a/Src/Tools/FolderCloner.cs b/Src/Tools/FolderCloner.cs new file mode 100644 index 0000000..7b179b5 --- /dev/null +++ b/Src/Tools/FolderCloner.cs @@ -0,0 +1,68 @@ +using System.Diagnostics; +using NativeFileDialogSharp; + +namespace BangumiRenamer.Tools; + +public static class FolderCloner +{ + public static void Run() + { + var result = Dialog.FolderPicker(); + if (!result.IsOk) return; + var source = result.Path; + + result = Dialog.FolderPicker(); + if (!result.IsOk) return; + var dest = Path.Combine(result.Path, Path.GetFileNameWithoutExtension(source)); + + var finalDest = dest; + int suffix = 1; + while (Directory.Exists(finalDest)) + { + finalDest = dest + suffix; + ++suffix; + } + + CloneStructureWithEmptyFiles(source, finalDest); + Process.Start(new ProcessStartInfo + { + FileName = finalDest, + UseShellExecute = true, + Verb = "open" + }); + } + + static void CloneStructureWithEmptyFiles(string source, string dest) + { + if (!Directory.Exists(source)) + { + return; + } + if (Directory.Exists(dest)) + { + return; + } + foreach (string subDirPath in Directory.GetDirectories(source, "*", SearchOption.AllDirectories)) + { + string newSubDirPath = subDirPath.Replace(source, dest); + Directory.CreateDirectory(newSubDirPath); + } + foreach (string filePath in Directory.GetFiles(source, "*", SearchOption.AllDirectories)) + { + string newFilePath = filePath.Replace(source, dest); + string directoryName = Path.GetDirectoryName(newFilePath); + if (!Directory.Exists(directoryName)) + { + Directory.CreateDirectory(directoryName); + } + try + { + using (File.Create(newFilePath)) { } + } + catch (Exception ex) + { + Console.WriteLine($"创建文件失败 {newFilePath}: {ex.Message}"); + } + } + } +} \ No newline at end of file