我正在尝试使用 ReadDirectoryChangesW API 使用 Python 在 Windows 上查看创建/删除/重命名更改的目录。这是我的代码,它工作正常:
results = win32file.ReadDirectoryChangesW(self.hDir, 8192, True, self.type, None,
None)
for action, file in results:
full_filename = os.path.join (self.source_path, file)
if action == 1: # Created
self.fileCreated(full_filename)
elif action == 2: # Deleted
self.fileDeleted(full_filename)
elif action == 3: # Updated
self.fileUpdated(full_filename)
elif action == 4: # Renamed from something
renamed_file = full_filename
elif action == 5: # Renamed to something
self.fileRenamed(renamed_file, full_filename)
但是,当我尝试从 python 或 Windows 资源管理器中删除监视的文件夹时,我得到:
WindowsError:[错误 32] 该进程无法访问该文件,因为它正被另一个进程使用:'c:\users\user\appdata\local\temp\new_dir'
我相信这是有道理的,但我应该如何解决这个问题?因为我的应用程序应该允许用户删除被监视的文件夹。我尝试了异步方法http://www.themacaque.com/?p=859的解决方案,但没有帮助。
提前致谢!