What's the relative order with which Windows search for executable files in PATH?

Jeenu picture Jeenu · Oct 31, 2009 · Viewed 18.5k times · Source

If I have a.com, a.cmd, a.bat, and a.exe files %PATH%, which one would Windows pick if I invoke just the command "a"? Is this officially spec-ed somewhere by M$?

I just wanted to wrap my gvim.exe executable with -n, but my gvim.bat doesn't appear to get run neither from the command line, nor from the Run dialog.

Answer

mjv picture mjv · Oct 31, 2009

See the command search sequence on Microsoft Docs

The PATH and PATHEXT environmental variables each provide an element of the search sequence: PATH is the ordered list of directories "where" to look, and PATHEXT is the ordered list of file extensions ("what") to look for (in case the extension isn't explicitly provided on the command line). Prior to using the PATH however, the current directory is searched.

The PATHEXT variable defaults to ".COM;.EXE;.BAT;.CMD"