简体   繁体   English

检测移动文件事件

[英]Detecting moved files events

I am trying to develop an application for monitoring operations on a particular folder which includes creating, deleting, modifying, moveing, duplicating and renaming. 我正在尝试开发一个用于监视特定文件夹上的操作的应用程序,包括创建,删除,修改,移动,复制和重命名。

After referring to the FileSystemWatcher API, I found that it does not provide a Move event, instead it will generate a separate Delete and Create events for the same file. 引用FileSystemWatcher API后,我发现它不提供Move事件,而是为同一文件生成单独的Delete和Create事件。 Of course I can wait for a Create event each time a Delete event is detected and decide whether it is a Move event or not, but it is a little bit strange to me and the appropriate time to wait for is also a problem. 当然,每次检测到Delete事件时,我都可以等待Create事件,并确定它是否为Move事件,但这对我来说有点奇怪,并且适当的等待时间也是一个问题。

Actually I find that Dropbox is able to detect the Move event correctly even when dropbox process is not running. 实际上,我发现即使Dropbox进程未运行,Dropbox仍能够正确检测Move事件。 Nice work for Dropbox team and I wonder how do they make it work on earth. Dropbox团队的工作做得很好,我想知道他们如何使它在地球上发挥作用。

So my purpose is quite clear : Filtering Move event from other events and making it work offline (which means when the procedure is stopped) 所以我的目的很明确:从其他事件中过滤Move事件并使它脱机工作(这意味着过程停止)。

Well, a move operation is basically a "copy & delete" from the FileSystemWatcher 's point of view. 好吧,从FileSystemWatcher的角度来看,移动操作基本上是“复制并删除”。 Without knowing details about the implementation I bet DropBox stores a hash for each file. 在不了解有关实现细节的情况下,我敢打赌DropBox为每个文件存储一个哈希。 If a file is removed in one place and created with the same hash in another place, chances are it was moved. 如果在一个位置删除了文件,然后在另一个位置创建了具有相同哈希的文件,则该文件很可能被移动了。 You could actually do the same thing. 您实际上可以做同样的事情。

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

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