0x0000001E
0x0000001E

Reputation: 414

Powershell nested IF statements

I am trying to do the following:

  1. Check for a file in src
    • If that file is there copy it to dst
    • If that file is exists in the dst, continue
    • If that file isn't in the dst, do something
  2. Continue on but do something else
  3. Finish off and do something else

I'm struggling to understand how the nested IF statements should be structured

Upvotes: 1

Views: 26862

Answers (1)

Micky Balladelli
Micky Balladelli

Reputation: 9991

Seems pretty straight given your requirements:

$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

Upvotes: 5

Related Questions