How-To Guide

    PowerShell Get-ChildItem: List Files in a Directory

    The Get-ChildItem parameters you actually need, tested examples for recursion, filtering and excluding folders, the -Include and -Exclude gotchas, and how to export the list to CSV.

    Published October 26, 2026Updated October 26, 20267 min read
    Mehrab Ali

    Author

    Mehrab Ali

    Founder & Executive Lead, ARCED International

    Founder of ARCED Foundation, ARCED International, and Solutions of Things Lab (SoTLab). Built FolderManifest to help teams protect file integrity and stay audit-ready.

    Quick Answer

    To list files in a directory with PowerShell, run Get-ChildItem -Path "C:\Folder" -File. Add -Recurse to include every subfolder, -Filter *.pdf to keep one file type, and -Force to show hidden files. Get-ChildItem is built into Windows PowerShell 5.1 and PowerShell 7, and ls, dir, and gci are aliases for it.

    Every example below was run in Windows PowerShell 5.1 on Windows 11 and works the same in PowerShell 7, including on macOS and Linux (where paths use / and the ls alias runs the native command instead).

    Get-ChildItem Basics

    Open the folder in File Explorer, click the address bar, type powershell, and press Enter. PowerShell opens in that folder. Then:

    # Files and folders in the current folder
    Get-ChildItem
    
    # A specific folder (quote paths with spaces)
    Get-ChildItem -Path "C:\Users\Me\Documents"
    
    # Files only, or folders only
    Get-ChildItem -File
    Get-ChildItem -Directory
    
    # Everything below this folder, all levels
    Get-ChildItem -Recurse -File
    
    # Just the names (relative paths when recursing)
    Get-ChildItem -Recurse -File -Name

    The default output shows Mode, LastWriteTime, Length (size in bytes), and Name. Those are properties of real objects, not text, which is why you can sort, filter, and export them in the next steps without parsing anything.

    Get-ChildItem Parameters You Will Use

    ParameterWhat it does
    -PathFolder to list. Accepts wildcards, e.g. C:\Logs\*.log. Defaults to the current folder.
    -LiteralPathLike -Path, but treats [ and ] as normal characters.
    -RecurseIncludes all subfolders.
    -DepthLimits recursion. -Depth 0 is the folder itself, -Depth 1 adds one level.
    -File / -DirectoryReturn only files or only folders.
    -FilterOne wildcard pattern, applied by the file system. The fastest way to match a type.
    -Include / -ExcludeSeveral patterns, applied by PowerShell to item names. See the gotchas below.
    -ForceAdds hidden and system items. -Hidden returns only hidden items.
    -NameOutputs name strings instead of file objects.

    Filter, Include, and Exclude (and Their Gotchas)

    # One file type, all subfolders
    Get-ChildItem -Recurse -File -Filter *.pdf
    
    # Several types: -Include needs -Recurse or a path ending in \*
    Get-ChildItem -Path .\* -Include *.jpg, *.png -File
    Get-ChildItem -Recurse -Include *.jpg, *.png -File
    
    # Everything except temp files
    Get-ChildItem -Recurse -File -Exclude *.tmp, *.bak

    Why -Include returns nothing

    Get-ChildItem -Include *.txt on its own returns no results, even when the folder is full of text files. Without -Recurse, -Include only applies when the path ends in a wildcard. Write -Path .\*, add -Recurse, or use -Filter when you only need one pattern.

    Why -Exclude doesn't skip a folder

    -Exclude node_modules hides the folder entry itself, but the files inside it still come back, because -Exclude compares each item's own name, not its path. To skip a whole folder, filter on the full path:

    Get-ChildItem -Recurse -File |
      Where-Object FullName -notmatch '\\node_modules\\|\\\.git\\'

    -notmatch takes a regular expression, so backslashes are doubled and the dot in .git is escaped.

    Useful Get-ChildItem Recipes

    # Count files and total size (MB)
    $m = Get-ChildItem -Recurse -File | Measure-Object -Property Length -Sum
    "$($m.Count) files, $([math]::Round($m.Sum / 1MB, 1)) MB"
    
    # 10 largest files
    Get-ChildItem -Recurse -File |
      Sort-Object Length -Descending |
      Select-Object -First 10 FullName, @{ n = 'MB'; e = { [math]::Round($_.Length / 1MB, 1) } }
    
    # Files changed in the last 7 days
    Get-ChildItem -Recurse -File |
      Where-Object LastWriteTime -gt (Get-Date).AddDays(-7)
    
    # How many files of each type
    Get-ChildItem -Recurse -File |
      Group-Object Extension -NoElement |
      Sort-Object Count -Descending
    
    # Folders only, two levels deep
    Get-ChildItem -Recurse -Directory -Depth 1 | Select-Object FullName

    Want exact duplicates? Pipe the list into Get-FileHash and group by hash; our Get-FileHash guide and finding duplicate files on Windows walk through it.

    Export the File List to CSV, Text, or the Clipboard

    # CSV that opens in Excel
    Get-ChildItem -Recurse -File |
      Select-Object FullName, Length, LastWriteTime |
      Export-Csv "$HOME\Desktop\files.csv" -NoTypeInformation
    
    # Plain text, one full path per line
    Get-ChildItem -Recurse -File |
      Select-Object -ExpandProperty FullName |
      Out-File "$HOME\Desktop\files.txt"
    
    # Copy the names to the clipboard
    Get-ChildItem -File -Name | Set-Clipboard

    Saving to the Desktop keeps the output file out of its own listing. For a drawing of the folder structure instead of a flat list, use the tree command; to print names on paper, see how to print a list of files in a folder.

    Access Denied Errors and Long Scans

    Recursing through C:\Users or a whole drive prints red Access to the path is denied errors for protected folders. The listing still finishes; add -ErrorAction SilentlyContinue to hide the noise, or -ErrorVariable errs to keep a list of what was skipped.

    On large trees, put the cheapest filter first: -Filter and -File are handled by the file system, while Where-Object runs on every item after it is loaded. Store the result once ($files = Get-ChildItem -Recurse -File) and reuse it instead of rescanning.

    When a File List Isn't Enough

    A Get-ChildItem export tells you which files exist. It can't tell you whether a copy matches the original: two lists can have the same names and sizes while one file was corrupted or replaced with an older version. Comparing two CSVs by hand also gets slow past a few hundred rows.

    FolderManifest builds a folder manifest: every file with its path, size, dates, and a SHA-256 hash, exported as HTML, CSV, or Markdown. Check a backup or migrated copy against it and it reports exactly which files were added, removed, or changed. It runs locally on Windows 10/11, macOS, and Linux.

    You may not need it

    For a one-off list or a quick script, Get-ChildItem is the right tool. A manifest is worth it when you have to prove a copy is complete and unchanged, or check the same folder again next month.

    Checking two folders right now? Follow our guide to comparing two folders on Windows.

    Frequently Asked Questions

    How do I list all files in a folder with PowerShell?

    Run Get-ChildItem -Path "C:\Folder" -File. Add -Recurse to include every subfolder. Get-ChildItem has the aliases gci, ls, and dir, so dir -File -Recurse does the same thing.

    Why does Get-ChildItem -Include return nothing?

    Without -Recurse, -Include only works when the path ends in a wildcard. Get-ChildItem -Include *.txt returns nothing, while Get-ChildItem -Path .\* -Include *.txt works. For a single pattern, -Filter *.txt is simpler and faster.

    How do I exclude a folder from Get-ChildItem -Recurse?

    -Exclude matches item names, so -Exclude node_modules still returns the files inside node_modules. Filter on the full path instead: Get-ChildItem -Recurse -File | Where-Object FullName -notmatch '\\node_modules\\'.

    How do I show hidden files with Get-ChildItem?

    Add -Force to include hidden and system items alongside normal ones. Use -Hidden to list only hidden items. Both work in Windows PowerShell 5.1 and PowerShell 7.

    How do I limit how deep Get-ChildItem goes?

    Use -Depth with -Recurse (PowerShell 5.0 or later). -Depth 0 returns only the folder itself, -Depth 1 adds one level of subfolders, and so on.

    How do I export the file list to Excel?

    Pipe it to Select-Object and Export-Csv: Get-ChildItem -Recurse -File | Select-Object FullName, Length, LastWriteTime | Export-Csv files.csv -NoTypeInformation. Excel opens the CSV directly.

    Go From a File List to Proof

    Record every file with its SHA-256 hash, then check any later copy against it. Windows, Mac, and Linux. 7-day free trial, no card required, 30-day money-back guarantee.

    Continue Learning