<http://www.netikka.net/tsneti/info/tscmd116.htm>
Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Sun 25-Apr-2010 08:06:04

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

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

A tangent question of a Unix "which" done with script commands is covered in item #46.

References/Comments: (If a Google message link fails try the links within the brackets.)
  Google Groups Sep 10 2005, 2:10 am [M]
  Google Groups Sep 10 2005, 6:20 am [M]