汎用機メモっとくか

しごと用の(学習メモ&お気に入り保存)。

でっきるかな?PowerShell 001

2016年11月28日 01時55分32秒 | PowerShell

<SampleIO.PS1>

$dlgOP = New-Object System.Windows.Forms.OpenFileDialog
$dlgSV = New-Object System.Windows.Forms.SaveFileDialog

$RC_Open = $dlgOP.ShowDialog()

$dlgSV.FileName = "aaa001.txt"
$RC_Save = $dlgSV.ShowDialog()

if(($RC_Open -eq 1) -and ($RC_Save -eq 1)){
    $path_IN   = $dlgOP.FileName
    $path_Out  = $dlgSV.FileName
   
    $oSR = New-Object System.IO.StreamReader $path_IN  , ([System.Text.Encoding]::GetEncoding("Shift_JIS"))
    $oSW = New-Object System.IO.StreamWriter $path_OUT , False ,([System.Text.Encoding]::GetEncoding("UTF-8"))
   
    while($oSR.Peek() -ne -1){
        $oSW.WriteLine($oSR.ReadLine())
    }
   
    $oSR.Close()
    $oSW.Close()
}

<20161129sta>

現場では、ps1ファイルの実行は大抵ふさがれているので、

Windows PowerShell ISE のコマンドウィンドウに貼り付けて実行

思い切りバグってました。Vistaで動くので、多分7でも大丈夫なはず

<20161129end>