shutil.move()从目录程序运行到目标文件夹
我很难获得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.
I'm having trouble getting shutil.move() working properly, I can use os.getcwd() to utilize the working directory, however I'm missing the '' that comes after the directory and before the file name, I've tried inputting a ` + '\' after the directory but it doesnt recognise this.
Error is below, missing the '' after GUI and before test.pdf.
FileNotFoundError: [Errno 2] No such file or directory: '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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本地文件以Windows中的
。\
开始。尝试
shutil.move(r'。\ test.pdf',r'z:\ test.pdf')
Local files start with
.\
in Windows.Try
shutil.move(r'.\test.pdf', r'Z:\test.pdf')