using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace GetADoc { class RunBatch { //ファイル名に使用不可の文字が含まれている場合の処理 public static string NameCalibration(string inFileName) { string[] charsToRemove = new string[] { @"\", ".", "/", ":", "*", "?", "<", ">", "|" }; foreach (var allNg in charsToRemove) { inFileName = inFileName.Replace(allNg, string.Empty); } return inFileName; } //バッチファイルの実行 public static void runBatch(bool icon, bool screen, bool sepa, bool free, bool language, string fileName, string filePath, string tempType) { //コンソール呼び出し ProcessStartInfo processStartInfo = new ProcessStartInfo(); string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; //モジュールのパスを取得 string appDirectory = appPath.Substring(0, appPath.LastIndexOf(@"\") + 1); //モジュールの存在するディレクトリを取得 processStartInfo.FileName = System.IO.Path.Combine(appDirectory, "getADoc.Data", "getADoc.bat"); processStartInfo.CreateNoWindow = true; // コマンドプロンプトを非表示 processStartInfo.UseShellExecute = false; // シェル機能オフ //チェックボックスの状況に応じて引数を指定 processStartInfo.Arguments = ""; if (icon == true)//Iconsチェックボックスがオンのとき { processStartInfo.Arguments += "/Icons "; } if (screen == true)//SCREEN Logoチェックボックスがオンのとき { processStartInfo.Arguments += "/SCREEN "; } if (sepa == true)//分割ドキュチェックボックスがオンのとき { processStartInfo.Arguments += "/SepaDoc "; } //freepageの有無 if (!free) { processStartInfo.Arguments += "/FreePage 0 "; } //言語選択 if (language)//ture:En flase:Jp { processStartInfo.Arguments += "/L en "; } //テンプレートの種別を判別 if (tempType == "QnA") { processStartInfo.Arguments += "/Template QA "; } else if (tempType == "基本設計資料" || tempType == "Basic Design") { processStartInfo.Arguments += "/Template BasicDesign "; } else if (tempType == "議事録" || tempType == "record of proceedings") { processStartInfo.Arguments += "/Template Meeting "; } else { processStartInfo.Arguments += "/Template Normal "; } //既存の生成物が指定先フォルダに存在する場合は上書きする processStartInfo.Arguments += "/Force "; var pathAndName = System.IO.Path.Combine(filePath, fileName); pathAndName = "\"" + pathAndName + "\""; processStartInfo.Arguments += pathAndName; //GetADoc.batを実行 Process process = Process.Start(processStartInfo); process.WaitForExit(); process.Close(); } /// /// ディレクトリを移動する。 /// /// 移動するディレクトリ /// 移動先のディレクトリ public static void MoveDirectory(string sourceDirName, string destDirName) { // コピー先のディレクトリがないかどうか判定する if (!Directory.Exists(destDirName)) { // コピー先のディレクトリを作成する Directory.CreateDirectory(destDirName); } // コピー元のディレクトリの属性をコピー先のディレクトリに反映する File.SetAttributes(destDirName, File.GetAttributes(sourceDirName)); // ディレクトリパスの末尾が「\」でないかどうかを判定する if (!destDirName.EndsWith(Path.DirectorySeparatorChar.ToString())) { // コピー先のディレクトリ名の末尾に「\」を付加する destDirName = destDirName + Path.DirectorySeparatorChar; } // コピー元のディレクトリ内のファイルを取得する string[] files = Directory.GetFiles(sourceDirName); foreach (string file in files) { // コピー元のディレクトリにあるファイルをコピー先のディレクトリにコピーする File.Copy(file, destDirName + Path.GetFileName(file), true); } // コピー元のディレクトリのサブディレクトリを取得する string[] dirs = Directory.GetDirectories(sourceDirName); foreach (string dir in dirs) { // コピー元のディレクトリのサブディレクトリで自メソッド(MoveDirectory)を再帰的に呼び出す MoveDirectory(dir, destDirName + Path.GetFileName(dir)); } Directory.Delete(sourceDirName, true);// 追加: 最後に元のフォルダを削除する } } }