本文介绍了在powershell中使用get-childitem -recurse,但将每个完整路径放在单独的行中(无需额外的目录行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我执行,例如

Get-ChildItem *.ext -recurse 

输出包含一系列Directory:条目,然后是每个匹配文件的一个条目.这对于许多目的很有用,但是今天我想要一个结果(类似于Unix find命令),其中每个匹配文件单独出现在一行上并显示其完整的相对路径(并且没有其他行出现).

the output consists of a series of Directory: entries followed by one entry for each each matching file. That's useful for many purposes, but today I'd like a result (analogous to the Unix find command) in which each matching file appears on a line by itself and shows its full relative path (and no other lines appear).

我搜索了一下,但没有找到解决方法.

I've searched a bit but haven't found a solution.

推荐答案

Get-ChildItem -Name开关可以满足您的要求:

Get-ChildItem's -Name switch does what you want:

  • 它将匹配文件相对路径(可能包括子目录组件)输出为字符串(类型为[string]).
  • It outputs the relative paths (possibly including subdir. components) of matching files as strings (type [string]).
# Lists file / dir. paths as *relative paths* (strings).
# (relative to the input dir, which is implicitly the current one here).
Get-ChildItem -Filter *.ext -Recurse -Name

注意事项:从PowerShell 7.0开始,-Name遭受性能问题和行为怪癖的困扰;请参阅以下GitHub问题:

Caveat: As of PowerShell 7.0, -Name suffers from performance problems and behavioral quirks; see these GitHub issues:

  • https://github.com/PowerShell/PowerShell/issues/9014
  • https://github.com/PowerShell/PowerShell/issues/9119
  • https://github.com/PowerShell/PowerShell/issues/9126
  • https://github.com/PowerShell/PowerShell/issues/9122
  • https://github.com/PowerShell/PowerShell/issues/9120

这篇关于在powershell中使用get-childitem -recurse,但将每个完整路径放在单独的行中(无需额外的目录行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 17:48