use get-childitem -recurse in powershell but get each full path on a separate line (without extra directory lines)

Question

If I execute, e.g.

Get-ChildItem *.ext -recurse 

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.

Solution

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

  • 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

Note that I've used -Filter, which significantly speeds up the traversal.

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