diff --git a/satella/os/misc.py b/satella/os/misc.py index 4f37be17a9e428eb8553cf6e5d6a4b641143ba32..ec4c8b8122b299d71375e92645b6761e625b56db 100644 --- a/satella/os/misc.py +++ b/satella/os/misc.py @@ -4,6 +4,8 @@ import os import sys import warnings +from satella.coding import silence_excs + def whereis(name: str) -> tp.Iterator[str]: """ @@ -25,17 +27,18 @@ def whereis(name: str) -> tp.Iterator[str]: available_extensions = '', for directory in paths_to_look_in: - for file in os.listdir(directory): - path = os.path.join(directory, file) - if 'x' not in stat.filemode(os.stat(path).st_mode): - continue - - if sys.platform.startswith('win'): # a POSIX-specific check - file = file.upper() # paths are not case-sensitive on Windows - - for extension in available_extensions: - if file == '%s%s' % (name, extension): - yield path + with silence_excs(FileNotFoundError): + for file in os.listdir(directory): + path = os.path.join(directory, file) + if 'x' not in stat.filemode(os.stat(path).st_mode): + continue + + if sys.platform.startswith('win'): # a POSIX-specific check + file = file.upper() # paths are not case-sensitive on Windows + + for extension in available_extensions: + if file == '%s%s' % (name, extension): + yield path def is_running_as_root() -> bool: