首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在组合System.IO.FileInfo对象时删除重复项

在组合System.IO.FileInfo对象时删除重复项
EN

Stack Overflow用户
提问于 2022-10-11 07:06:12
回答 1查看 49关注 0票数 -1

我正在尝试将System.IO.FileInfo对象(来自不同的Get调用)组合在一起。我从这个问题中找到了工作解决方案(即使用PowerShell数组):Combine the results of two distinct Get-ChildItem calls into single variable to do the same processing on them

代码语言:javascript
复制
$target = "C:\example"

$Files = @( Get-ChildItem -LiteralPath $target -Force -Attributes !D )
$Files += @( Get-ChildItem -LiteralPath $target -Force -Attributes !D ) # for demo. & simplicity, I'm using the same path here

$Files | Write-Host # here the same entries are duplicated

但是,来自System.IO.FileInfo对象的相同条目在结果对象中重复。我想知道是否有一种优雅的方法在删除副本的同时组合这些对象?

PS:如果文件具有相同的".FullName“,文件就会被”复制“。

EN

回答 1

Stack Overflow用户

发布于 2022-10-11 07:26:18

代码语言:javascript
复制
$Files = @($Files | Sort-Object -Property FullName -Unique)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74024225

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档