1

I have a simply batch that iterates files within a directory as suggested here:

cd "c:/TheDirectory"
for /f %%i in (*) do echo %%i

However when I execute this I get the following error:

Unable to find file *

When I execute this within a shell-promt I get the files within the directory.

Am I missing anything?

Community
  • 1
  • 1
MakePeaceGreatAgain
  • 33,293
  • 6
  • 51
  • 100

2 Answers2

1

For such a basic task/requirement then maybe this is all you need:

For %%i In (C:\TheDirectory\*.*) Do Echo %%~nxi

Also note the backslash which is common notation in DOS\Win. (you can use doublequotes if your directory has spaces "C:\The Directory\*.*")

Compo
  • 34,184
  • 4
  • 22
  • 36
0

You should write it like that :

@ECHO OFF
cd "c:\Test"
for /r %%i in (*) do echo %%i
pause

For more info about FOR /R to loop through files (Recurse subfolders)

EDIT : on 06/09/2016 @19:18

To show only files without recursion :

@echo off
set "Folder=%windir%"
for /f "delims=" %%i in ('Dir /A-D /b "%Folder%\*.*"') do echo %Folder%\%%i
pause & exit
Hackoo
  • 16,942
  • 3
  • 35
  • 62