找到目录中的最后一个文件
def search_index_file(search_dir=None,index=None):
if search_dir is None:
search_dir = '/'
print(search_dir)
result = search_dir
if index is not None:
index = int(index)
dirs = sorted(os.listdir(search_dir))[index]
path_file = os.path.join(search_dir,dirs)
if os.path.isdir(path_file):
result=search_index_file(search_dir=path_file,index=index)
else:
result = path_file
#这里的return很有意义,第二次进入search_index_file的return result是 找到文件的else返回的结果
#该结果给第一次执行search_index_file的if os.path.isdir(path_file)的result,
# 这时候第二次执行return result就是整个最终的结果
return result