Windows 10

Batch File To List Folder Names

In this tutorial, we are going to see how to list folder names by using For Loop. The 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 Folder Names

The following example list folder names with full path:

@echo off

for /d %%D in (*) do echo %%~fD

Output:

C:\Users\StackHowTo\Docs
C:\Users\StackHowTo\Images
C:\Users\StackHowTo\Download

If you want to list just the folder names without full path use %%~nxD instead of %%~fD.
 

 

Example 2: Batch File To List Folder Names

The following example list folder names without full path:

@echo off

for /d %%D in (*) do echo %%~nxD

Output:

Docs
Images
Download

 

Leave a Reply

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