Finds the first parent directory that contains a given file or directory.