動作確認
Windows 8.1 pro (64bit)
http://qiita.com/7of9/items/eac10683cdcca10b34f6
でParamにてフォルダ情報を渡せることが分かった。
次はフォルダ情報が渡されていないときにgracefullyに処理を終えるための対策として、stringのNULL, emptyチェック。
http://stackoverflow.com/questions/13738634/how-can-i-check-if-a-string-is-null-or-empty-in-powershell
にある回答のうちstringのstaticメソッドである
[string]::IsNullOrEmpty($scriptDir)
を使ってみた。
code
160130_nullStringCheck.ps1
Param(
[String]$scriptDir
)
function checkStringIsNull()
{
if ( [string]::IsNullOrEmpty($scriptDir) ) {
"NULL"
} else {
"$scriptDir"
}
}
function main()
{
checkStringIsNull
}
main
実行結果
> powershell .\160130_nullStringCheck.ps1
NULL
> powershell .\160130_nullStringCheck.ps1 -scriptDir C:\ZyboDev
C:\ZyboDev
動いた。これでいこう。
それにしても、PowerShellのウィンドウ内の文字列をコピペできない問題はどうにかしたい。Qiitaの記事にするために再度入力するのは面倒だし、打ち間違いもしそうだ。