Use expand_path instead of dirname.