PowerShell: How to Use ‘tree’ Command to Show Files


You can use the tree command in PowerShell to display the folder structure of a particular directory:

tree

By default, the tree command only shows the names of folders.

However, you can add the /f parameter to also display the names of the files in each folder:

tree /f

The following example shows how to use this syntax in practice.

Example: How to Use ‘tree’ Command to Show Files in PowerShell

Suppose that our current directory has the following path:

  • c:\users\bobbi\data1

Suppose we use the tree command to view the folder structure of our current directory:

tree

The following screenshot shows how to use this syntax in practice:

We can see that our current directory has the following structure:

├───athletes
├───coaches
└───managers
    ├───admin
    └───roster

There are three folders inside of the data1 folder named athletes, coaches and managers.

Within the managers folder, there are two folders named admin and roster.

Notice that only the folder names are shown and no files within the folders.

We can use the /f parameter to show the file names as well:

tree /f

The following screenshot shows how to use this syntax in practice:

PowerShell tree show files

Notice that the output now shows the folder names along with the files inside of each folder.

For example, we can see that the athletes folder contains the following files:

  • new_data.txt
  • old_data.txt

We can also see that the coaches folder contains the following file:

  • records.txt

And so on.

Note: You can find the complete documentation for the tree command in PowerShell here.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Sort Files in Folder by Size
PowerShell: How to Get Folder Size in GB
PowerShell: How to List Files in Directory by Date
PowerShell: How to Get Most Recently Modified File in Directory

Leave a Reply