list files in cmd code example

Example 1: cmd files in directory

Enter “dir” (without quotes) to list the files and folders contained in the folder.

Example 2: how to get list folder in cmd to value

@echo off
setlocal disableDelayedExpansion
set "files=."
for /r %%F in (*) do (
  setlocal enableDelayedExpansion
  for /f "delims=" %%A in ("!files!") do (
    endlocal
    set "files=%%A "%%F"
  )
)
(set files=%files:~2%)

Example 3: how to get list folder in cmd to value

for /f "eol=: delims=" %%F in ('dir /b /o:n') do set /p =""%%F","

Tags:

Misc Example