admin管理员组文章数量:1302967
I need to list recursively all files with paths, but without the lines for folders, something like this:
dir-name1\file-name1.ext
dir-name1\file-name2.ext
dir-name2\file-name3.ext
dir-name2\file-name4.ext
I use Powershell 2.0 that doesn't recognize some modern syntax. I've tried many suggested solutions, but none works. If it excludes folders, it also removes the file path; if it keeps the path, it doesn't exclude folders.
The only workaround I have so far with the obvious limitations is:
Get-ChildItem -Recurse -Name -Include *.*
Is there a better way without the complexity of writing a script?
I need to list recursively all files with paths, but without the lines for folders, something like this:
dir-name1\file-name1.ext
dir-name1\file-name2.ext
dir-name2\file-name3.ext
dir-name2\file-name4.ext
I use Powershell 2.0 that doesn't recognize some modern syntax. I've tried many suggested solutions, but none works. If it excludes folders, it also removes the file path; if it keeps the path, it doesn't exclude folders.
The only workaround I have so far with the obvious limitations is:
Get-ChildItem -Recurse -Name -Include *.*
Is there a better way without the complexity of writing a script?
Share Improve this question asked Feb 11 at 7:50 safespheresafesphere 1464 bronze badges 5 |1 Answer
Reset to default 1As promised, here my comment as short answer.
In PowerShell version 2.0, the Get-ChildItem
cmdlet doesn't have switches for -File
or -Directory
, so in order to get a listing of just files and no directories, you need to filter the DirectoryInfo objects out using a Where-Object
clause:
Get-ChildItem -Path D:\Test -Recurse | # enumerate ALL objects in the path
Where-Object { !$_.PsIsContainer } | # filter to receive only FileInfo objects
Select-Object -ExpandProperty FullName # return only the full path and file names
If you upgrade your now ancient version of PowerShell to at least version 5.1, you can get the same result (just faster) like this:
(Get-ChildItem -Path D:\Test -Recurse -File).FullName
本文标签:
版权声明:本文标题:recursion - How to exclude folders from a recursive list of pathname with Get-ChildItem in Powershell 2.0 (similar to dir s b a- 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741672028a2391660.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Get-ChildItem -Path D:\Test -Recurse | Where-Object { !$_.PsIsContainer } | Select-Object -ExpandProperty FullName
– Theo Commented Feb 11 at 10:23