Powershell嵌套IF语句
我正在努力做到以下几点:Powershell嵌套IF语句,powershell,if-statement,Powershell,If Statement,我正在努力做到以下几点: 在src 如果该文件存在,请将其复制到dst 如果该文件存在于dst中,请继续 如果该文件不在dst中,请执行某些操作 继续,但做点别的 结束并做些别的事情 考虑到您的需求,我很难理解嵌套IF语句的结构应该是怎样的 $src = "e:\temp" $dst = "e:\temp2" $filename = "test.txt" # 1.Check for a file in src if (Test-Path "$src\$filename") { #
src
- 如果该文件存在,请将其复制到dst
- 如果该文件存在于
中,请继续dst
- 如果该文件不在
中,请执行某些操作dst
考虑到您的需求,我很难理解嵌套IF语句的结构应该是怎样的
$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
考虑到您的要求,这似乎很简单:
$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