OS。将文件重命名到错误的文件夹中

问题描述 投票:0回答:1

我正在运行一个脚本,该脚本使用selenium和Pyautogui从chrome下载文件,然后重命名。它已成功重命名,但是文件已移至Pycharm Projects。如何保存下载或将其移动到另一个文件夹?非常感谢PS。我是一个完整的初学者,因此对愚蠢的错误表示歉意。

我在重命名后尝试了shutil.move(),但是我没有必要的权限,因为该文件当前位于PyCharm项目中。

import datetime
import glob
import os
import datetime
currentDT = datetime.datetime.now()
xcel_title_ = currentDT.strftime("%d.%m.%Y")
current_time = now.strftime("%H.%M.%S")
NF_Name = xcel_title_ + '_' + current_time + '.xlsx'
list_of_files = glob.glob(r'C:\Users\LouisKempson\Downloads\*') 
latest_file = max(list_of_files, key=os.path.getctime)
print(latest_file)
Excel_Title = ('Sign_In_Summary_' + NF_Name)

os.rename(latest_file,Excel_Title)
list_of_files = glob.glob(r'C:\Users\LouisKempson\Downloads*') # * means 
all if need specific format then *.csv
latest_file = max(list_of_files, key=os.path.getctime)
print(Excel_Title)
print(latest_file)`
python python-3.x operating-system
1个回答
0
投票

您需要在Excel_Title中包含目录前缀:

Excel_Title = os.path.join(r'C:\Users\LouisKempson\Downloads', 'Sign_In_Summary_' + NF_Name)
© www.soinside.com 2019 - 2024. All rights reserved.