When you need to list all the files in a folder, along with their paths and sizes, you can easily achieve this using both Command Prompt and PowerShell on Windows.
Table of contents
This guide will show you how to save these details into a CSV file, which you can then open using software like Microsoft Excel.
Using Command Prompt for Basic File List
Step 1: Open Command Prompt
Press the Windows key + R to open the Run dialog box. Type cmd and press Enter or click OK.
Step 2: Navigate to the Folder
Browse to the folder you want to list the files from. Use the cd command to change directories. For example:
cd C:\Path\To\Your\Folder
Step 3: Execute the Command
Type in and execute the following command:
dir /b /s > basic_output.csv
This command lists all the files and folders in the current directory and its subdirectories. The full paths of the files will be saved in a CSV file called basic_output.csv.
Using PowerShell for Detailed File List
Step 1: Open PowerShell
Press the Windows key + X and select “Windows PowerShell” from the menu.
Step 2: Navigate to the Folder
Browse to the folder you want to list the files from. Use the cd command, just like in Command Prompt:
cd C:\Path\To\Your\Folder
Step 3: Execute the Command
Type in and execute the following command:
Get-ChildItem -Recurse | Select-Object FullName, Length | Export-Csv -Path "detailed_output.csv" -NoTypeInformation
This PowerShell command provides a detailed list, including the full paths and file sizes. All these details will be saved in a CSV file named detailed_output.csv.
Note:
- Always ensure you’re in the correct directory before running commands.
- Both Command Prompt and PowerShell commands are case-insensitive on Windows