68 lines
1.9 KiB
C#
68 lines
1.9 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));
|
|
|
|
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}");
|
|
}
|
|
}
|
|
}
|
|
} |