powershell 如果检查多个文件的条件可用
powershell if condition to check multiple files are available
我只想在目录中的所有文件都可用时才复制文件。
在这种情况下,我想在 if 条件下检查它。
没用。
$File1 = "C:\Users\xx\Desktop\test.txt"
$File2 = "C:\Users\xx\Desktop\test.txt"
$Ziel = "C:\Users\xx\Desktop\test\a"
if(Test-Path -Path $File1 -and Test-Path -Path $File2)
{
Move-Item -Path $File1 -Destination $Ziel
Move-Item -Path $File2 -Destination $Ziel
}
您需要添加括号,条件如下:
$File1 = "C:\stack\A.txt"
$File2 = "C:\stack\B.txt"
$Ziel = "C:\stack\copy"
if((Test-Path -Path $File1) -and (Test-Path -Path $File2))
{
Move-Item -Path $File1 -Destination $Ziel
Move-Item -Path $File2 -Destination $Ziel
}
您也可以试试下面的脚本块。
$File1 = "C:\stack\A.txt"
$File2 = "C:\stack\B.txt"
$Ziel = "C:\stack\copy"
if(Test-Path -Path $File1,$File2)
{
Move-Item -Path $File1 -Destination $Ziel
Move-Item -Path $File2 -Destination $Ziel
}
我只想在目录中的所有文件都可用时才复制文件。 在这种情况下,我想在 if 条件下检查它。 没用。
$File1 = "C:\Users\xx\Desktop\test.txt"
$File2 = "C:\Users\xx\Desktop\test.txt"
$Ziel = "C:\Users\xx\Desktop\test\a"
if(Test-Path -Path $File1 -and Test-Path -Path $File2)
{
Move-Item -Path $File1 -Destination $Ziel
Move-Item -Path $File2 -Destination $Ziel
}
您需要添加括号,条件如下:
$File1 = "C:\stack\A.txt"
$File2 = "C:\stack\B.txt"
$Ziel = "C:\stack\copy"
if((Test-Path -Path $File1) -and (Test-Path -Path $File2))
{
Move-Item -Path $File1 -Destination $Ziel
Move-Item -Path $File2 -Destination $Ziel
}
您也可以试试下面的脚本块。
$File1 = "C:\stack\A.txt"
$File2 = "C:\stack\B.txt"
$Ziel = "C:\stack\copy"
if(Test-Path -Path $File1,$File2)
{
Move-Item -Path $File1 -Destination $Ziel
Move-Item -Path $File2 -Destination $Ziel
}