我無法讓 shutil.move() 正常作業,我可以使用 os.getcwd() 來利用作業目錄,但是我缺少目錄之后和檔案名之前的 '',我已經嘗試在目錄后輸入 ` '\' 但它無法識別。
錯誤如下,在 GUI 之后和 test.pdf 之前缺少“”。FileNotFoundError:[Errno 2] 沒有這樣的檔案或目錄:'Z:\PyCharm\GUItest.pdf'
output_folder = input()
source_dir = os.getcwd()
if os.path.isfile(f'{output_folder}test.pdf'):
print('File already exists, saved to your Z drive!')
shutil.move(f'{source_dir} test.pdf', 'Z:\') # needs to look in directory the program is ran from.
else:
shutil.move(f'{source_dir} test.pdf', output_folder) # same as above.
uj5u.com熱心網友回復:
本地檔案以 Windows 開頭.\。嘗試shutil.move(r'.\test.pdf', r'Z:\test.pdf')
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/485481.html
