dot/scripts/rename.csx
2023-12-13 18:43:53 +08:00

27 lines
923 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#r "nuget: NSExt, 1.1.0"
using NSExt.Extensions;
Console.WriteLine("请输入原始名称Dot");
var oldName = Console.ReadLine().NullOrEmpty("Dot");
Console.WriteLine("请输入替换名称:");
var newName = Console.ReadLine();
foreach (var path in Directory.EnumerateDirectories("../", $"*{oldName}*",
SearchOption.AllDirectories))
{
Console.($"{path} --> ");
var newPath = path.Replace(oldName, newName);
Directory.Move(path, newPath);
Console.WriteLine(newPath);
}
Console.WriteLine();
foreach (var path in Directory.EnumerateFiles("../", $"*.*", SearchOption.AllDirectories))
{
File.WriteAllText(path, File.ReadAllText(path).Replace(oldName, newName));
var newPath = path.Replace(oldName, newName);
if (newPath == path) continue;
Console.($"{path} --> ");
Directory.Move(path, newPath);
Console.WriteLine(newPath);
}