Powershell 嵌套 IF 语句

0x0*_*01E 1 powershell if-statement

我正在尝试执行以下操作:

  1. 检查文件 src
    • 如果该文件在那里,请将其复制到 dst
    • 如果该文件存在于 中dst,则继续
    • 如果该文件不在 中dst,请执行某些操作
  2. 继续但做其他事情
  3. 完成并做其他事情

我正在努力理解嵌套的 IF 语句应该如何构建

Mic*_*lli 5

鉴于您的要求,这似乎很直接:

$src = "e:\temp"
$dst = "e:\temp2"
$filename = "test.txt"

# 1.Check for a file in src
if (Test-Path "$src\$filename")
{
    # 1.A If that file is there copy it to dst
    Copy-Item "$src\$filename" $dst

    if (!(Test-Path "$dst\$filename"))
    {
        # 1.C If that file isn't in the dst do something
    }
    #1.B If that file exists in the dst continue
}
else
{
    #2.Continue on but do something else
}

#3.Finish off and do something else
Run Code Online (Sandbox Code Playgroud)