1

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

1 Answer 1

5

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.