Python 获取指定目录所有深层文件路径(包括子目录下的所有文件)
import os
def get_all_deep_files_in_folder(folder_path):
all_files = []
file_paths = os.listdir(folder_path)
for item in file_paths:
fp = os.path.join(folder_path,item)
if os.path.isfile(fp):
all_files.append(fp)
else:
all_files = all_files + get_all_deep_files_in_folder(fp)
return all_files
all_files = get_all_deep_files_in_folder(folder_path)
采用递归调用的实现方式,使用时自己指定folder_path即可
欢迎在评论区给出更好方法