16 lines
315 B
Python
16 lines
315 B
Python
import os
|
|
|
|
def find_nearest(path, test):
|
|
path = os.path.abspath(path)
|
|
|
|
while True:
|
|
parent_path = os.path.dirname(path)
|
|
for entry in os.listdir(path):
|
|
if test(entry):
|
|
return path
|
|
|
|
if parent_path == path:
|
|
return None
|
|
|
|
path = parent_path
|