Commits

TK Soh  committed 9878e3e

context: refactor _find_path()

  • Participants
  • Parent commits 1c9eda3

Comments (0)

Files changed (1)

File tortoise/contextmenu.py

             return self._handlers[cmd][0]
         return S_FALSE
 
-    def _find_path(self, pgmname):
-        ospath = os.environ['PATH']
-        plist = []
-        for path in ospath.split(';'):
-            for ext in ['exe', 'bat', 'cmd']:
-                ppath = os.path.join(path, "%s.%s" % (pgmname, ext))
-                #print "checking path: %s" % ppath
+    def _find_path(self, pgmname):
+        """ return first executable found in search path """
+        ospath = os.environ['PATH'].split(os.pathsep)
+        pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD')
+        pathext = pathext.lower().split(os.pathsep)
+
+        for path in ospath:
+            for ext in pathext:
+                ppath = os.path.join(path, pgmname + ext)
                 if os.path.exists(ppath):
-                    plist.append(ppath)
+                    return ppath
 
-        if plist:
-            #print "path found: %s" % ", ".join(plist)
-            return plist[0]
-        else:
-            return None
+        return None
 
     def _run_program(self, appName, cmdline):
         # subprocess.Popen() would create a terminal (cmd.exe) window when