如何使用python检查文件是否已完全下载到文件夹中
我正在编写一个python脚本,负责组织您的下载文件夹,将每种类型的文件安排在一个单独的文件夹中。我正在使用watchdog检查下载文件夹中的修改。如果有任何东西开始下载,脚本将运行,尽管我希望在运行脚本之前等待下载完成 我不知道如何使用python检查下载文件是否完全下载 我已经包含了代码来说明我的脚本基本上是如何工作的如何使用python检查文件是否已完全下载到文件夹中,python,python-3.x,operating-system,python-watchdog,Python,Python 3.x,Operating System,Python Watchdog,我正在编写一个python脚本,负责组织您的下载文件夹,将每种类型的文件安排在一个单独的文件夹中。我正在使用watchdog检查下载文件夹中的修改。如果有任何东西开始下载,脚本将运行,尽管我希望在运行脚本之前等待下载完成 我不知道如何使用python检查下载文件是否完全下载 我已经包含了代码来说明我的脚本基本上是如何工作的 class ShiftingFiles(FileSystemEventHandler): """ This class is going to allow us to ove
class ShiftingFiles(FileSystemEventHandler):
"""
This class is going to allow us to override the FileSystemEventHandler
methods.
"""
# Overriding the on_modified() method of FileSystemEventHandler class
# in the watchdog API
def on_modified(self, event):
self.shift()
if __name__ == "__main__":
# To shift the files as soon as the program is run
ShiftingFiles().shift()
# Consuming watchdog API
event_handler = ShiftingFiles()
observer = Observer()
observer.schedule(event_handler, download_location, recursive=False)
observer.start()
try:
while True:
time.sleep(1000)
except KeyboardInterrupt:
observer.stop()
observer.join()
<>这不是我想的更好的解决方案,但是你可以看到最后修改日期在1分钟的间隔,如果是相同的,考虑文件已经完成。 < P>我有一个类似的问题,这对我来说已经解决了。在处理文件之前,请等待文件传输完成:
def on_modified(self, event):
file_size = -1
while file_size != os.path.getsize(event.src_path):
file_size = os.path.getsize(event.src_path)
time.sleep(1)
self.shift()
请看介绍教程。添加一些你的东西代码,这样用户可以帮助轻松检查,这是有意义的,我会试试看!我不知道如何使用它来确定文件是否已经下载@Todd。我没有使用python下载任何东西。使用浏览器完成下载。我只是想看看它什么时候被完全下载。