Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List All Executables in any of your environment PATHs using Batch

Is there a way to list all executables available with your current PATH (environment variable) setting with a batch file?

I've been trying for a while and I can't seem to find a way (i ain't no batch intellectual).

Please help if you can even a link to an article can be useful. Thank you!

like image 516
Issam Rafihi Avatar asked Jan 03 '23 02:01

Issam Rafihi


2 Answers

surprisingly simple:

for %a in (%pathext%) do where *%a

the %pathext% lists all defined file extension that are executable (.exe, .bat, ...) and where lists all findings within the %path%

Note: this is command line syntax. For use in a batch file, use %%a instead of %a

like image 64
Stephan Avatar answered Jan 05 '23 17:01

Stephan


As an addition to the already provided answer, and as a result of @aschipfl's comment, the following should use only the locations defined in the %Path% environment variable, and not include the current directory, (unless that itself was in %Path%).

From the Command Prompt:

For %A In (%PathExt%) Do @Where $Path:*%A 2>Nul

And from a batch file:

@For %%A In (%PathExt%) Do @Where $Path:*%%A 2>Nul

Obviously if you were only looking for .exe files as opposed to executables it would be much simpler:

Where $Path:*.exe 2>Nul
like image 39
Compo Avatar answered Jan 05 '23 15:01

Compo