71 lines
2.0 KiB
C#
71 lines
2.0 KiB
C#
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.Replace("\\\\", "")));
|
|
|
|
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;
|
|
}
|
|
var queue = new Queue<string>();
|
|
queue.Enqueue(source);
|
|
while (queue.Count > 0)
|
|
{
|
|
var dir = queue.Dequeue();
|
|
try
|
|
{
|
|
foreach (var filePath in Directory.GetFiles(dir))
|
|
{
|
|
var newFilePath = Path.Combine(dest, Path.GetRelativePath(source, filePath));
|
|
using var _ = File.Create(newFilePath);
|
|
}
|
|
|
|
foreach (var dirPath in Directory.GetDirectories(dir))
|
|
{
|
|
queue.Enqueue(dirPath);
|
|
var newDirPath = Path.Combine(dest, Path.GetRelativePath(source, dirPath));
|
|
Directory.CreateDirectory(newDirPath);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Clone失败 {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
} |