【问题标题】:Return only files with Get-childitem in powershell 2 [duplicate]在powershell 2中仅返回带有Get-childitem的文件[重复]
【发布时间】:2016-09-25 16:00:16
【问题描述】:

我知道我们可以在 Powershell V3.0 中使用参数 -File 但我们如何才能在 Powershell V2 中使用 Get-childitem cmdlet 仅获取文件?

【问题讨论】:

  • 骗子涵盖的内容更多,但您的具体问题的答案仍然存在。
  • @Matt 最简单的Get-ChildItem -File 未在据称重复中提及。
  • @JosefZ 为什么会这样?这个问题是关于不存在 -File 开关的 PowerShell 2.0。我确实找到了另一个包含这样一个答案的答案,但我选择的那个看起来更相关,并且“其他”信息更少。

标签: windows powershell powershell-2.0 cmdlets cmdlet


【解决方案1】:

您可以使用Where-Object cmdlet 来检查PSIsContainer 属性:

Get-ChildItem  | Where-Object { !$_.PSIsContainer }

【讨论】:

  • 好的,我试试,但它也适用于未命名的文件吗?
  • 未命名文件是什么意思?
  • 我的意思是没有扩展名的文件
  • 很确定您需要在 v2 中使用括号。
  • 哦,谢谢马特,我更新了我的答案。
猜你喜欢
  • 2019-08-26
  • 2020-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多