shutil.move()从目录程序运行到目标文件夹

发布于 2025-02-03 20:48:30 字数 563 浏览 3 评论 0原文

我很难获得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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

未蓝澄海的烟 2025-02-10 20:48:30

本地文件以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')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文