MicroRos编译修复脚本
由于未知原因MicroROS STM32版本编译完成后文件目录非常乱,导致直接使用会找不到头文件或者提示头文件冲突,故写了这个C#脚本用来修复
C#脚本
var path = "";//改为build路径
string[] files = System.IO.Directory.GetFiles(path, "*", System.IO.SearchOption.AllDirectories);
foreach (var fileOrigin in files)
{
var file = fileOrigin.Replace("\\", "/");
var singleFile = file.Split("/");
for (int i = 0; i < singleFile.Length-1; i++)
{
if (singleFile[i]== singleFile[i+1])
{
Console.ForegroundColor = ConsoleColor.DarkRed;
var source = file;
Console.WriteLine(source);
Console.ForegroundColor = ConsoleColor.DarkGreen;
var dist = file.Replace($"/{singleFile[i]}/{singleFile[i]}", $"/{singleFile[i]}");
Console.WriteLine(dist);
Console.WriteLine();
if (!Directory.Exists(file.Replace($"{singleFile[singleFile.Length - 1]}", ""))) ;
{
Directory.CreateDirectory(dist.Replace($"{singleFile[singleFile.Length - 1]}", ""));
}
File.Move(source,dist,true);
}
}
}
var dirs= Directory.GetDirectories(path,"*",System.IO.SearchOption.AllDirectories);
foreach (var dir in dirs)
{
if (Directory.GetFiles(dir,"*",SearchOption.AllDirectories).Length == 0)
{
Directory.Delete(dir,true);
}
}