Stefan Glova
Stefan Glova

Reputation: 127

How to use "tree" command on powershell to show files as well as directories

I am trying to get full structure of my project in tree format in powershell. When I use the command tree, it only shows directories and subdirectories, but neither files nor hidden folders, such as .git

How can I show files as well?

Thank you

Upvotes: 2

Views: 7117

Answers (1)

mklement0
mklement0

Reputation: 439777

tree.com:

  • does have an option to include files in the output: /F

  • does not have an option to include hidden directories and files - they are invariably excluded.[1]


Solutions:

  • This answer contains an custom PowerShell function named tree that extends the functionality of tree.com and whose -Force switch allows you to include hidden items.

  • The Get-PSTree cmdlet from the third-party PSTree module (install with, e.g., Install-Module PSTree) also supports -Force and offers even more features.


[1] I'm referring to files and directories on Windows that have the Hidden attribute, which is unrelated to whether their names start with . (e.g., .gitignore; it is only on Unix-like platforms that the latter are automatically considered hidden). You can set the Hidden attribute with attrib +H someDir, for instance, and clear it with attrib -H someDir. tree.com does not show such hidden items.

Upvotes: 4

Related Questions