[英]I cannot move files from one folder to another with shutil.move after several attempts
[英]shutil.move() move from directory program is ran from, to target folder
我無法讓 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.
本地文件在 Windows 中以.\
開頭。 試試shutil.move(r'.\test.pdf', r'Z:\test.pdf')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.