This page is edited from the 1cmdfaq.txt faq-file contained in
my tscmd.zip
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
companion.
Please see "
The Description and
the Index page" for the conditions of usage and other such
information.
116} How do I get a list all the *.BAT files which are at path?
@echo off & setlocal enableextensions
for %%a in ("%path:;=" "%") do (
for /f %%f in ('dir /b /a:-d /o:n "%%~a\*.bat"') do (
echo %%~a\%%f)
)>>"%temp%\temp.dir"
for %%c in (type del) do call %%c "%temp%\temp.dir"
endlocal & goto :EOF
There is, however an even better solution which avoids the "File not
found" problem for folders that contain no *.BAT files. The snippet
is from the references at the end of this item.
@echo off & setlocal enableextensions
for %%a in ("%path:;=" "%") do (
for %%g in ("%%~a\*.bat") do echo %%~fg)
endlocal & goto :EOF
or, relevantly for any command-line files
@echo off & setlocal enableextensions
for %%a in ("%path:;=" "%") do (
for %%g in ("%%~a\*.bat" "%%~a\*.cmd") do echo %%~fg)
endlocal & goto :EOF
A tangent question of a Unix "which" done with script commands is
covered in item
#46.