我有一个文件名列表1和一个全名列表2(带有路径)
我需要提取list1中现有的list2中的所有元素。用简单的英语,所有文件都在两边列出,并带有完整路径
我试过了
$filenames = @('index.jsp','index1.jsp', 'index2.jsp')
$fullpaths = Get-ChildItem -rec . | where { ! $_.PSIsContainer }
$common = $fullpaths | Where { $p = $_.FullName; foreach ($n in $filenames) { $p -match $($n + "$") } }
$common | foreach { Write-Output $_ }
但是它将所有文件输出到中。
如何正确使用Where来将一个元素与另一个列表中的所有元素进行匹配?
我不知道你是不是想那样
$filenames = @('index.jsp','index1.jsp', 'index2.jsp')
$common = Get-ChildItem -Recurse -File | where Name -In $filenames
$common.FullName
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句