我只想验证文件夹 1 中的文件是否也位于文件夹 2 中。我只需要验证文件名。出于测试目的,我知道它们是相同的文件,但我无法得到相同的结果。此外,我需要排除文件夹 1 中的一个 *.txt 文件,我之前也从未成功过,甚至在我的两个示例中都没有包含它。我知道这应该很简单,但我一直很纠结。如果这很重要,我正在测试的 zip 文件名是 N324RA_TEST__20240423221326.zip 和 N335RT_TEST_20250410020632.zip。这些文件肯定在文件夹 1 中,我需要验证它们是否也在文件夹 2 中。如果其中一个或两个不在文件夹 2 中,我需要知道
我尝试过:
$Temp = "C:\MaxTemp\"
$Temp2 = "C:\MaxTemp2\"
$files1 = Get-ChildItem -Path $Temp -Recurse | Where-Object { ! $_.PSIsContainer }
$files2 = Get-ChildItem -Path $Temp2 -Recurse | Where-Object { ! $_.PSIsContainer }
write-host "$files1"
write-host "$files2"
if ($fiiles1 -eq $files2)
{write-host "same"
}
else
{write-host "not same"}
这导致文件不一样。我也试过了,但不管怎样,它找到的文件都是一样的。
$Temp = "C:\MaxTemp\"
$Temp2 = "C:\MaxTemp2\"
$files1 = Get-ChildItem -Path $Temp -Recurse | Where-Object { ! $_.PSIsContainer }
$files2 = Get-ChildItem -Path $Temp2 -Recurse | Where-Object { ! $_.PSIsContainer }
if ($comparison) {
Write-Host "Differences found:"
$comparison | ForEach-Object {
if ($_.SideIndicator -eq "<=") {
Write-Host "Only in $($Temp): $($_.Name)"
}
}
}
else{ ($_.SideIndicator -eq "==")
Write-Host "No differences found. Both folders contain the same files."
}