【问题标题】:How to use the continue in a loop if variable is empty in Powershell 2.0?如果 Powershell 2.0 中的变量为空,如何在循环中使用 continue?
【发布时间】:2013-10-21 11:32:36
【问题描述】:

在我的脚本中使用 continue 语句时,我需要一些建议。

我的脚本在我的备份文件夹中搜索特定备份文件,然后创建一个 sql 命令来恢复该特定备份。

如果找不到备份,我的脚本就会崩溃。因此,如果变量为空,我需要在循环中继续。如何正确定义?

if ($specificmarketbackupfile -eq "")
        {
            continue
        }

这没有成功,所以我需要什么?提前致谢。

【问题讨论】:

    标签: loops powershell foreach powershell-2.0


    【解决方案1】:

    我会尝试 Test-Path 或 Contains。不过,Test-Path 应该是最好的路线。

    If (!(Test-Path $specificmarketbackupfile))
       {
          Commands Here
       }
    

    这将返回一个布尔值 True 或 False 来判断它是否看到定义的文件/目录。

    【讨论】:

      猜你喜欢
      • 2021-07-27
      • 2013-01-01
      • 1970-01-01
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多