DOSのTYPEコマンドを使ってVB.NETでファイルのマージを行うサンプル
Dim objProcess As Process = New System.Diagnostics.Process 'cmd.exeのパスを取得 objProcess.StartInfo.FileName = System.Environment.GetEnvironmentVariable("ComSpec") objProcess.StartInfo.RedirectStandardInput = False objProcess.StartInfo.RedirectStandardOutput = True objProcess.StartInfo.UseShellExecute = False 'シェルでファイル追記コマンドを実行 objProcess.StartInfo.Arguments = " /c TYPE """ & "D:\hoge.txt" & """ >> """ & "D:\hogeMerge.txt" & """" objProcess.Start() Dim results As String = objProcess.ExitCode objProcess.WaitForExit() 'コマンドの実行結果をチェック If results <> "0" Then msgbox = "ファイルの追記を失敗しました。:" & objProcess.StartInfo.Arguments End If
動作確認環境:Visual Stadio 2005,Window Server 2008