How to List Directories and Files in PowerShell

To list directories and files in PowerShell, use Get-ChildItem. On its own, it lists every folder and file in the current location. Add -Directory for folders only, -File for files only and -Recurse to include subfolders.

Here it is on a sample Projects folder I created for this article:

Get-ChildItem -Path C:\psfaqs\Projects

Output:

    Directory: C:\psfaqs\Projects

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----           8/14/2026 11:00 AM                Archive
d----           9/20/2026  5:45 PM                Reports
d----           9/20/2026  5:45 PM                Scripts
d----           9/20/2026  5:45 PM                Website
-a---            9/1/2026  9:30 AM          48213 Budget-2026.xlsx
-a---            9/3/2026  9:30 AM           1200 notes.txt
Get-ChildItem listing directories and files of a folder in PowerShell 7
Get-ChildItem on the sample Projects folder

The Mode column tells you what each item is. A d means directory, a means the archive attribute is set (a normal file), and h would mean hidden.

dir, ls and gci are aliases for Get-ChildItem, so dir C:\psfaqs\Projects returns the same list. I tested everything in PowerShell 7.6 and Windows PowerShell 5.1.

List only directories in PowerShell

Add the -Directory switch to skip the files:

Get-ChildItem -Path C:\psfaqs\Projects -Directory

Output:

    Directory: C:\psfaqs\Projects

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----           8/14/2026 11:00 AM                Archive
d----           9/20/2026  5:45 PM                Reports
d----           9/20/2026  5:45 PM                Scripts
d----           9/20/2026  5:45 PM                Website
Get-ChildItem -Directory listing only folders in Windows PowerShell 5.1
Folders only, in Windows PowerShell 5.1

List only files

-File does the opposite and returns only files:

Get-ChildItem -Path C:\psfaqs\Projects -File

Output:

    Directory: C:\psfaqs\Projects

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---            9/1/2026  9:30 AM          48213 Budget-2026.xlsx
-a---            9/3/2026  9:30 AM           1200 notes.txt

Notice that .env is missing. It’s a hidden file, and I’ll show you how to include those in a moment.

List files and folders recursively

-Recurse walks every subfolder. Combine it with -File and pick the columns you care about:

Get-ChildItem -Path C:\psfaqs\Projects -Recurse -File |
    Select-Object FullName, Length |
    Format-Table -AutoSize

Output:

FullName                                        Length
--------                                        ------
C:\psfaqs\Projects\Budget-2026.xlsx              48213
C:\psfaqs\Projects\notes.txt                      1200
C:\psfaqs\Projects\Reports\Q3-sales.csv           7766
C:\psfaqs\Projects\Reports\Q3-sales.pdf         154880
C:\psfaqs\Projects\Scripts\backup.ps1             3120
C:\psfaqs\Projects\Scripts\cleanup.ps1            1874
C:\psfaqs\Projects\Scripts\logs\backup-0926.log    912
C:\psfaqs\Projects\Website\index.html             5310
C:\psfaqs\Projects\Website\styles.css             2048
C:\psfaqs\Projects\Website\images\logo.png       18432

On a large drive, recursion can take a while. Point -Path at the folder you actually need instead of the root of C:\.

Limit how deep Get-ChildItem goes

-Depth controls how many levels below the starting folder you get. -Depth 0 is just the top level, and -Depth 1 adds one more:

Get-ChildItem -Path C:\psfaqs\Projects -Directory -Recurse -Depth 0 | Select-Object -ExpandProperty Name
'---'
Get-ChildItem -Path C:\psfaqs\Projects -Directory -Recurse -Depth 1 | Select-Object -ExpandProperty FullName

Output:

Archive
Reports
Scripts
Website
---
C:\psfaqs\Projects\Archive
C:\psfaqs\Projects\Reports
C:\psfaqs\Projects\Scripts
C:\psfaqs\Projects\Website
C:\psfaqs\Projects\Scripts\logs
C:\psfaqs\Projects\Website\images

I always pair -Depth with -Recurse. It makes the intent obvious to the next person who reads the script.

List file and folder names only

When you need plain text, for example to paste into an email or feed another command, add -Name. You get relative paths instead of objects:

Get-ChildItem -Path C:\psfaqs\Projects -Recurse -Name

Output:

Archive
Reports
Scripts
Website
Budget-2026.xlsx
notes.txt
Reports\Q3-sales.csv
Reports\Q3-sales.pdf
Scripts\logs
Scripts\backup.ps1
Scripts\cleanup.ps1
Scripts\logs\backup-0926.log
Website\images
Website\index.html
Website\styles.css
Website\images\logo.png

How do I list hidden files in PowerShell?

Get-ChildItem skips hidden and system items unless you add -Force:

(Get-ChildItem -Path C:\psfaqs\Projects -File).Name
'--- with -Force ---'
(Get-ChildItem -Path C:\psfaqs\Projects -File -Force).Name

Output:

Budget-2026.xlsx
notes.txt
--- with -Force ---
.env
Budget-2026.xlsx
notes.txt

If you only want the hidden items, use -Hidden instead. I cover more cases in how to list hidden files in PowerShell.

Filter by file type

-Filter is the fastest way to match one pattern, because the file system does the filtering:

Get-ChildItem -Path C:\psfaqs\Projects -Recurse -Filter *.ps1 | Select-Object Name, Directory

Output:

Name        Directory
----        ---------
backup.ps1  C:\psfaqs\Projects\Scripts
cleanup.ps1 C:\psfaqs\Projects\Scripts

For several patterns, use -Include. There’s a catch, though. -Include only works together with -Recurse or a path that ends in a wildcard:

Get-ChildItem -Path C:\psfaqs\Projects -Include *.csv, *.pdf    # no -Recurse: returns nothing
'--- with -Recurse ---'
(Get-ChildItem -Path C:\psfaqs\Projects -Include *.csv, *.pdf -Recurse).Name

Output:

--- with -Recurse ---
Q3-sales.csv
Q3-sales.pdf

The first command returns nothing and doesn’t raise an error, which makes this easy to miss. The Get-ChildItem documentation mentions it in the parameter notes.

Sort files by size or date

Every file comes back as an object with Length (in bytes) and LastWriteTime, so sorting is one command. These are the three largest files:

Get-ChildItem -Path C:\psfaqs\Projects -Recurse -File |
    Sort-Object Length -Descending |
    Select-Object -First 3 Name, @{ Name = 'SizeKB'; Expression = { [math]::Round($_.Length / 1KB, 1) } }, LastWriteTime

Output:

Name              SizeKB LastWriteTime
----              ------ -------------
Q3-sales.pdf     151.200 9/19/2026 9:30:00 AM
Budget-2026.xlsx  47.100 9/1/2026 9:30:00 AM
logo.png          18.000 9/9/2026 9:30:00 AM

Swap Length for LastWriteTime to see the newest files first.

Count the files and folders

PSIsContainer is $true for folders, so you can count both in one pass:

$items = Get-ChildItem -Path C:\psfaqs\Projects -Recurse
"Folders: $(($items | Where-Object PSIsContainer).Count)"
"Files:   $(($items | Where-Object { -not $_.PSIsContainer }).Count)"

Output:

Folders: 6
Files:   10

Show a folder tree

Windows still ships the classic tree /f command, and it works in PowerShell. If you want the tree as PowerShell output you can filter or save, a small recursive function does the job:

function Show-Tree {
    param([string]$Path = '.', [string]$Indent = '')
    $items = Get-ChildItem -Path $Path | Sort-Object { -not $_.PSIsContainer }, Name
    for ($i = 0; $i -lt $items.Count; $i++) {
        $last   = $i -eq $items.Count - 1
        $branch = if ($last) { '\-- ' } else { '+-- ' }
        $items[$i].Name | ForEach-Object { "$Indent$branch$_" }
        if ($items[$i].PSIsContainer) {
            Show-Tree -Path $items[$i].FullName -Indent ($Indent + $(if ($last) { '    ' } else { '|   ' }))
        }
    }
}

'Projects'
Show-Tree -Path C:\psfaqs\Projects

Output:

Projects
+-- Archive
+-- Reports
|   +-- Q3-sales.csv
|   \-- Q3-sales.pdf
+-- Scripts
|   +-- logs
|   |   \-- backup-0926.log
|   +-- backup.ps1
|   \-- cleanup.ps1
+-- Website
|   +-- images
|   |   \-- logo.png
|   +-- index.html
|   \-- styles.css
+-- Budget-2026.xlsx
\-- notes.txt
PowerShell function showing a folder tree with files
A folder tree built with Get-ChildItem in PowerShell 7

Export the list of files to CSV

For an inventory or an audit, send the file list to Export-Csv. You can open the result in Excel:

Get-ChildItem -Path C:\psfaqs\Projects -Recurse -File |
    Select-Object Name, DirectoryName, Length, LastWriteTime |
    Export-Csv -Path C:\psfaqs\project-files.csv -NoTypeInformation

"Saved $((Import-Csv C:\psfaqs\project-files.csv).Count) rows to project-files.csv"

Output:

Saved 10 rows to project-files.csv

Frequently Asked Questions

What is the PowerShell command to list files in a directory?

Get-ChildItem -Path C:\Folder -File. Leave out -File to list folders too, and add -Recurse to include subfolders.

How do I list only folders in PowerShell?

Add the -Directory switch: Get-ChildItem -Path C:\Folder -Directory.

Is dir the same as Get-ChildItem in PowerShell?

Yes. dir, ls and gci are aliases for Get-ChildItem, but CMD switches like dir /s don’t work. Use -Recurse instead.

Why does -Include return nothing?

-Include needs -Recurse or a path that ends in \*, such as C:\Folder\*. Otherwise it silently returns nothing.

How do I get only file names without the full path?

Use -Name, or select the property with (Get-ChildItem -File).Name.

More file and folder tutorials: