Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell嵌套IF语句_Powershell_If Statement - Fatal编程技术网

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