Powershell - how do I list files and write their path into an output file?
Asked Answered
T

2

9

I want to list *.xml files which are in several subdirectories. Then I want to write their path and their names into an txt file. I managed to write the names into an txt file, however, I have no idea how to add their paths. What do I need to change/add?

Get-ChildItem path -recurse -include *.xml| ForEach-Object { $_.Name } > path\output.txt

Thank you for your help! Cheers, Iris

Thunderclap answered 16/1, 2014 at 13:40 Comment(0)
F
15

FullName will print the full path to the file.

Get-ChildItem path -recurse -include *.xml| ForEach-Object { $_.FullName } > path\output.txt

Here's a list of properties that the object returned in this instance provides: FileInfo Class

Fredericton answered 16/1, 2014 at 13:46 Comment(0)
C
0

Try this as well, slightly more "PowerShell" preferred syntax:

Get-ChildItem -File -Path 'D:\code*' -Filter '*.xml' -Recurse | ForEach-Object { $_.FullName } | Out-File -Append "D:\code\xmlFileList.txt"
Complexioned answered 19/8 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.