简体   繁体   English

Python shutil.move 无休止地复制

[英]Python shutil.move copies endlessly

I made a script that reads pdf-files from a src-folder, gets some info from the file and then renames the file and moves it to another location.我制作了一个脚本,它从 src 文件夹中读取 pdf 文件,从文件中获取一些信息,然后重命名文件并将其移动到另一个位置。 This is done every 5 seconds.这是每 5 秒完成一次。

Since the src and dest are on different disks I use shutil.move instead of os.rename.由于 src 和 dest 位于不同的磁盘上,我使用 shutil.move 而不是 os.rename。

Because src and dest are on a different disk shutil.move wil instead copy and delete the source file.因为 src 和 dest 位于不同的磁盘上,shutil.move 将改为复制和删除源文件。

The script works fine, but sometimes there are problems with permissions in the source folder.该脚本工作正常,但有时源文件夹中的权限存在问题。 This keeps the source file in the source folder and is copied endlessly because the source file can't get deleted.这将源文件保留在源文件夹中,并且由于无法删除源文件而被无休止地复制。

How can I work around this?我该如何解决这个问题? Since I don't keep the name of the original pdf-files I don't know how to solve this.由于我不保留原始 pdf 文件的名称,我不知道如何解决这个问题。

在此处输入图像描述

Have you considered keeping track of when you last moved files, and then only moving source files with later modification timestamps?您是否考虑过跟踪上次移动文件的时间,然后只移动具有后来修改时间戳的源文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM