5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Powershell > stringが(NULLまたはempty)かどうか > if ( [string]::IsNullOrEmpty($scriptDir) ) { ... / Powershellでコピペ: コメント参照

Last updated at Posted at 2016-01-29
動作確認
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の記事にするために再度入力するのは面倒だし、打ち間違いもしそうだ。

5
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?