MRTKのソースリストをcsv形式に変換するVisual Studioのコンソールアプリ 参考:https://www.hiromukato.com/entry/2020/06/13/004434
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System.Text; | |
namespace MRTKSourceListCreator | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Assetsフォルダで以下DOSコマンドを実行して出力したファイル | |
// > dir /B /S *.cs > csFileList.txt | |
string filePath = "csFileList.txt"; | |
// 出力するファイル名 | |
string outfilePath = "output.csv"; | |
StringBuilder sb = new StringBuilder(); | |
// テキストファイルを読み込む | |
if (File.Exists(filePath)) | |
{ | |
using (var reader = new StreamReader(filePath, Encoding.UTF8)) | |
{ | |
while (!reader.EndOfStream) | |
{ | |
var line = reader.ReadLine(); | |
var csvStr = ConvertLine(line); | |
sb.Append(csvStr + "\n"); | |
} | |
} | |
} | |
// ファイルへの出力 | |
using (var writer = new StreamWriter(outfilePath)) | |
{ | |
writer.Write(sb.ToString()); | |
} | |
} | |
// MRTKフォルダ配下のパスをcsv形式の文字列に変換する | |
static string ConvertLine(string line) | |
{ | |
// ファイルを開き行数をカウントする | |
int lineCount = File.ReadAllLines(line).Length; | |
var words = line.Split('\\'); | |
// MRTKフォルダまで何階層かを取得 | |
int rootIndex = 0; | |
foreach (var word in words) | |
{ | |
if (word == "MRTK") | |
{ | |
break; | |
} | |
rootIndex++; | |
} | |
string pathes = ""; | |
string fileName = ""; | |
for (int i = rootIndex+1; i < words.Length; i++) | |
{ | |
if (i == words.Length - 1) | |
{ | |
fileName = words[i]; | |
break; | |
} | |
pathes += words[i] + ","; | |
} | |
// 行数,ファイル名,パス1,パス2... のフォーマットで出力 | |
return lineCount.ToString() + "," + fileName + "," + pathes.TrimStart(','); | |
} | |
} // class Program | |
} // namespace MRTKSourceListCreator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment