4

i would like to list all the directories down to a specified level with the Tree command. I like the way the Tree command sorts and uses the ASCII to show the directories or folders, and all the folders within those folders.

This is what i have so far. I would like to modify this command with like -Depth 2 or something like that. This command as it stands works great for listing all the directories but i only want them down to a certain level. I hope this helps you help me:)

Tree | Select-Object -Skip 2 | Set-Content list20.txt

3

1 Answer 1

5

Tree is not a PowerShell cmdlet, as we know, and as such cannot be used in the vein you are trying to do.

For what you are after, you have to write this yourself or look for something already done.

You cannot filter external .exe(s) as you can with say Get-ChildItem, and such, without capturing all its output as an object then, using the normal object walking efforts available.

If you search for such solutions, you'd come across these examples:

PowerTip: Limit Get-Childitem to a limited depth in the tree

Get-Childitem C:\Users\CurlyBlue -include *.docx -depth 2

PowerTip: View Directory List as Tree by Using PowerShell

Show-Tree e:\data –depth 2

Powershell Directory Tree

get-childitem -Path Q:\ -Recurse -Directory -Depth 3|select FullName|export-csv C:\file-tree.csv


# or this way

(get-childitem -Path d:\projects -Recurse -Directory -Depth 2).FullName

There are a number of other options to dig at this as well. All searchable on the web.

For example: See also

List contents of directories in a tree-like format with colorization and lots of options

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .