JSI Tip 8947. How can list the executable, or non-executable, files is a directory tree?


I have scripted Executable.bat to list the executable, or non-executable, files is a folder.

The syntax for using Executable.bat is:

Executable Folder \[/s\] \[/n\]

Where:

Folder is the path to the directory you wish to enumerate.

/s     is an optional parameter that enumerates sub-folders.

/n     is an optional parameter that lists non-executable files, instead of executable files.
NOTE: Executable.bat uses the PATHEXT environment variable to determine what extensions are executable.

Executable.bat contains:

@echo off
if \{%1\}

\{\} @echo Syntax: Executable Folder \[/s\] \[/n\]&goto :EOF if not exist %1 Executable - %1 NOT found.&goto :EOF setlocal set folder=%1# set folder=%folder:"=% set folder=%folder:\#=% set folder=%folder:#=% set sw=/i if /i \{%2\}

\{/s\} set sub=/s if /i \{%2\}

\{/n\} set sw=%sw% /v if /i \{%3\}

\{/s\} set sub=/s if /i \{%3\}==\{/n\} set sw=%sw% /v set exec=%PATHEXT:;= % for /f "Tokens=*" %%a in ('dir "%folder%" /b /a %sub%^|findstr %sw% "%exec%"') do ( if /i "%sub%" NEQ "/s" ( @echo "%folder%\%%a" ) ELSE ( @echo "%%a" ) ) endlocal



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish