find_executable
- pyhelpers.dirs.find_executable(name, options=None, target=None)[source]
Get pathname of an executable file for a specified application.
- Parameters:
name (str) – name or filename of the application that is to be called
options (list | set | None) – possible pathnames or directories, defaults to
None
target (str | None) – specific pathname (that may be known already), defaults to
None
- Returns:
whether the specified executable file exists and its pathname
- Return type:
tuple[bool, str]
Examples:
>>> from pyhelpers.dirs import find_executable >>> import os >>> python_exe = "python.exe" >>> possible_paths = ["C:\Program Files\Python39", "C:\Python39\python.exe"] >>> python_exe_exists, path_to_python_exe = find_executable(python_exe, possible_paths) >>> python_exe_exists True >>> os.path.relpath(path_to_python_exe) 'venv\Scripts\python.exe' >>> text_exe = "pyhelpers.exe" # This file does not actually exist >>> test_exe_exists, path_to_test_exe = find_executable(text_exe, possible_paths) >>> test_exe_exists False >>> os.path.relpath(path_to_test_exe) 'pyhelpers.exe'