檢查os
和os.path
模塊上市文件夾的內容(walk
,listdir
),並與路徑名(abspath
,basename
等)
工作同時,shutil
有複製的東西了一些有趣的功能。檢出copyfile
並根據您從Excel文件中讀取的數據指定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)
你必須使用xlrd
模塊提供extract_filename_from_excel_file
自己從我提到的網站。
你能從文件中提取公司名稱等嗎?即您的問題是關於重命名還是關於從文件中獲取數據?另外,你有什麼嘗試? –