Windows 10

Batch File to List All Files in a Folder and Subfolders

In this tutorial, we are going to see how to list all files in a folder and subfolders using batch file. Batch file contains a series of DOS (Disk Operating System) instructions. It allows triggering the execution of commands found in this file.
 

Example 1: Batch File to List All Text Files in a Folder and Subfolders

The following example list all text files in a folder and subfolders:

@echo off

forfiles /s /m *.txt /c "cmd /c echo @relpath"

Output:

".\file1.txt"
".\file2.txt"
".\myFolders\test1.txt"
".\myFolders\test2.txt"

 

 

Example 2: Batch File to List All Files in a Folder and Subfolders

The following example list all text files in a folder and subfolders:

@echo off

forfiles /s /m *.* /c "cmd /c echo @relpath"

Output:

".\file1.txt"
".\file2.txt"
".\image.png"
".\myFolders\nature.jpg"
".\myFolders\test1.txt"
".\myFolders\test2.txt"

 

Leave a Reply

Your email address will not be published. Required fields are marked *