It's pretty simple actually if you understand the for command. @echo off setlocal EnableDelayedExpansion for /f %%a in ('dir /b /a-d') do ( echo %%a pause )