【发布时间】:2020-06-26 23:16:41
【问题描述】:
我正在编写一个 python 脚本,该脚本负责通过将每种类型的文件安排在一个单独的文件夹中来组织您的下载文件夹。我正在使用看门狗检查下载文件夹中的修改。如果有任何东西开始下载,脚本就会运行,尽管我想等到下载完成后再运行我的脚本。
我不知道如何检查下载文件是否完全使用 python 下载。
我已包含代码以显示我的脚本的基本工作原理。
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()
【问题讨论】:
-
请参阅介绍导览中的How to Ask。
-
添加一些你的东西代码,以便用户可以轻松地提供帮助
标签: python python-3.x operating-system python-watchdog