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
  • 35,491
  • 6
  • 60
  • 111

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
  • 36,585
  • 5
  • 27
  • 39
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
  • 18,337
  • 3
  • 40
  • 70