Everyday Documents

Home|Articles

Print File and Folder Paths to a Text Document

Learn how to use the command line to output a directory list of files and folders for analysis and future reference.

Dec 31, 2022 - 2 min read

Lists can be useful

Introduction

Having a raw list of files and folders can be helpful for many things, such as auditing your documents and taking a snapshot of your files for archiving purposes. There are dedicated pieces of software that can perform this action, however in the era of malware and ransomware a DIY approach feels safer. Below are steps to perform this task using the trusty Command Prompt.

Step 1: Open the command line

To get started search for cmd in the Windows start menu, and open the Command Prompt app.

Open the command prompt from the start menu

Step 2: Navigate to the directory

Type cd in the command prompt, followed by a space and then the folder address, for example cd C:\Users. Press enter to complete the directory change. The easiest way to add the folder address is to copy it from File Explorer, and then paste it into the command line.

Change the directory using 'cd'

Step 3: Create the list

Type the following command: dir /s /b > out.txt. A text file called 'out.txt' will be saved to the directory you have just scanned.

Source: Stack Overflow

Print the directory to a text file

Bonus: PowerShell Script

The above task can be completed with a short PowerShell script:

#User input
$path = Read-Host "Please enter the path to scan"

#Scan path
Get-ChildItem -Path $path -Recurse | Select-Object -ExpandProperty FullName | Write-Host
Get-ChildItem -Path $path -Recurse | Select-Object -ExpandProperty FullName > "filelist.txt"

#Pause output
Read-Host -Prompt "Press Enter to continue"

Why is this useful?

Now that we can create directory lists, here are some things we can do with our new power:

  • Search for duplicate files
  • Find and delete old files and folders
  • Identify long file names and folder paths
  • Make a list of your music collection

Latest Articles

Show more articles