添加工具
This commit is contained in:
parent
321f037fa2
commit
358cc33f3a
@ -16,6 +16,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="NativeFileDialogSharp" Version="0.5.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
68
Src/Tools/FolderCloner.cs
Normal file
68
Src/Tools/FolderCloner.cs
Normal file
@ -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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user