Search code examples
cpathqualified-name

How do you find the fully qualified path name of a file?


On Windows, you can go to "Run," type in "cmd," press enter, and start up "C:\Windows\system32\cmd.exe" rather easily. The same is true for "python" or "pythonw" (though nothing pops up in the second example). If all you know is that you want to execute "python" or "pythonw" and that it is on the PATH, what is the simplest way in C to figure out the fully qualified path name for the executable? This question seems to be highly related to the problem but does not give a final solution in C. _execp allows using the string "python" or "pythonw" but requires the qualified path for the first argument to the argv parameter of the function.


Solution

  • Have a look at the shell APIs PathResolve (that, however, is marked as "removable in any future windows version", so I'd avoid it) and PathFindOnPath, that, instead, is a stable API. With PathFindOnPath, pass the filename to search (e.g. yourexecutable.exe) as the first parameter and NULL as the second one.