检查os
andos.path
模块以列出文件夹内容 ( walk
, listdir
) 并使用路径名 ( abspath
,basename
等)
此外,shutil
还有一些有趣的复制东西的功能。根据您从 excel 文件中读取的数据签出copyfile
并指定参数。dst
此页面可以帮助您获取 Excel 数据: http: //www.python-excel.org/
你可能想要一些像这样的高级代码:
for subfolder_name in os.listdir(MAIN_FOLDER):
# exercise left to reader: filter out non-folders
subfolder_path = os.path.join(MAIN_FOLDER, subfolder_name)
for excel_file_name in os.listdir(os.path.join(MAIN_FOLDER, subfolder_name)):
# exercise left to reader: filter out non-excel-files
excel_file_path = os.path.join(subfolder_path, excel_file_name)
new_excel_file_name = extract_filename_from_excel_file(excel_file_path)
new_excel_file_path = os.path.join(NEW_MAIN_FOLDER, subfolder_name,
new_excel_file_name)
shutil.copyfile(excel_file_path, new_excel_file_path)
您必须使用我提到的站点中extract_filename_from_excel_file
的模块来提供自己。xlrd