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