'EEM-STF計算バッチ処理プログラム:stf_sol.vbs '株式会社EEM ' '目的: '指定したフォルダにある.stfデータをすべて計算し、 '計算結果を同名の.outファイルに出力する。 'sol.logファイルを連結しsol_all.logファイルに出力する。 ' '使用法: '> cscript stf_sol.vbs データフォルダ Option Explicit '次の行を編集すること(計算コマンド) Const cmd = "stf2.exe -n 2" 'CPUのとき、数字はコア数 'Const cmd = "stf2g.exe" 'GPUのとき Const ext = "stf" '拡張子 Const outlog = "sol_all.log" '出力されるlogファイル(変更可) Dim objShell, objFS, objFolder, objLog, objText Dim fn, num, strout, datafolder 'フォルダ名を引数から取得する If WScript.Arguments.Count = 1 Then datafolder = WScript.Arguments(0) Else WScript.Echo "使い方: cscript stf_sol.vbs データフォルダ" WScript.Quit 1 End If Set objShell = CreateObject("Wscript.Shell") Set objFS = CreateObject("Scripting.FileSystemObject") 'フォルダ If Not objFS.FolderExists(datafolder) Then WScript.Echo "フォルダ " & datafolder & " が存在しません" WScript.Quit 1 End If Set objFolder = objFS.GetFolder(datafolder) '出力logファイル If objFS.FileExists(outlog) Then objFS.DeleteFile outlog End If Set objLog = objFS.CreateTextFile(outlog) '計算コマンド確認 WScript.Echo "計算コマンド : " & cmd 'データファイルに関するループ num = 0 For Each fn In objFolder.Files '拡張子チェック If objFS.GetExtensionName(fn) = ext Then 'ファイル名表示 num = num + 1 WScript.Echo num & " " & objFS.GetFileName(fn) & " " & Now() '計算 objShell.Run cmd & " " & fn, 0, True '0:ウィンドウなし、True:同期 'sol.outコピー strout = datafolder + "\" + objFS.GetBaseName(fn) + ".out" If objFS.FileExists(strout) Then objFS.DeleteFile strout End If objFS.CopyFile "sol.out", strout 'sol.log連結 Set objText = objFS.OpenTextFile("sol.log", 1) '1 : read only objLog.Write objText.ReadAll End If Next If num = 0 Then WScript.Echo "フォルダ " & datafolder & " に" & ext & "ファイルがありません" End If