Find a executable file path programmatically and fast

Viewed 3079

I want to find a .exe files path programatically in Java, for example:

  • Skype.exe is entered into a program to find the direct path to it
  • Program does an algorithm that finds the file path
  • Program returns the file path C:\Users\Public\Desktop\Skype.exe

A method I have tried is sorting through the systems files until "skype.exe" is found, but that takes up a lot of time and resources.

Is there any hack that could make it almost instant, like maybe a Win_Api function/cmd command or is sorting through the file system until the program is found the only way?

3 Answers

If you want to know WHICH executable is being executed from the command line when you type . Use the which/where commands..

Unix/linux/Mac OSX Possix <which>

which chmod which cd which ls which myprogram

returns returns nothing if no such program file exists.

for Windows use where <where> /? for help on this command

If you don't have an executable but an alias or some sort of environment function/procedure/shell command.. use the <type> command on Unix/linux/Mac OS X. That will tell yo if you are dealing with an alias, environment function, or executable.

Related