Find the first file matching in a given directory or the nearest ancestor directory up to root