C:\_G\WWW\~ELISANET\INFO\tscmd116.html
<http://www.elisanet.fi/tsalmi/info/tscmd116.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Sun 4-Nov-2018 09:51:44

 
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
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.

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]

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd116.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd116
http://www.elisanet.fi/tsalmi/info/tscmd116.html
file:///c:/_g/www/~elisanet/info/tscmd116.html