1

This is what I have but its not correct.

(Get-Content C:\Users\U0146121\Desktop\Output.txt) |
ForEach-Object {
Compare-Object -referenceobject $_ -DifferenceObject $(get-content C:\Users\U0146121\Desktop\New folder\filenames.txt) -IncludeEqual
}

I want to compare the current line and see if it is in the filenames.txt If it is then write the name to a new txt file.

4

2 回答 2

4

你不需要循环。

Compare-Object -ReferenceObject (Get-Content .\Two.txt) -DifferenceObject (Get-Content .\One.txt) -IncludeEq
ual | Where {$_.SideIndicator -eq '=='}  | Select -ExpandProperty InputObject | Out-file C:\same.txt
于 2013-07-16T16:42:53.897 回答
1

这看起来类似于比较两个数组并获取不常见的值

将每个文件的内容放到一个集合$Ref = (Get-Content $origFile); $New = (Get-Content $NewFile);中。确保两个列表都包含相同级别的路径引用(绝对路径与具有相同深度的相对路径)。然后比较两个集合对象。

于 2013-07-16T16:41:16.020 回答