Return the filename or parent directory path of a file or directory by walking up parent directories.