简体   繁体   English

在文件资源管理器中检测并记录复制/粘贴/删除/剪切操作

[英]Detect and Log copy/paste/delete/cut operations in File Explorer

I want to detect and log to file Explorer operations such as copy/cut/delete/paste. 我想检测并登录到文件资源管理器操作,例如复制/剪切/删除/粘贴。

I have read about FileSystemWatcher , but I also noticed it has some issues since there is no copy/cut events available which can be confusing with whatever I want to do. 我已经阅读了有关FileSystemWatcher ,但我也注意到它存在一些问题,因为没有可用的复制/剪切事件,这些事件可能会使我想做的事情感到困惑。

The operating system and FileSystemWatcher object interpret a cut-and-paste action or a move action as a rename action for a folder and its contents. 操作系统和FileSystemWatcher对象将剪切和粘贴操作或移动操作解释为文件夹及其内容的重命名操作。 If you cut and paste a folder with files into a folder being watched, the FileSystemWatcher object reports only the folder as new, but not its contents because they are essentially only renamed. 如果将包含文件的文件夹剪切并粘贴到正在监视的文件夹中,则FileSystemWatcher对象仅将文件夹报告为新文件夹,而不报告其内容,因为它们实际上仅被重命名。

FileSystemWatcher is hooking the create file and delete file events to the changed and renamed events which can't really help me to determine if it was made by the user or some another process. FileSystemWatcher创建文件删除文件事件挂接到更改重命名的事件上,这并不能真正帮助我确定它是由用户还是其他进程创建的。 Furthermore I cannot be 100% sure what happened to the file whether it was copied or cut etc. 此外,我不能100%确定文件是被复制还是剪切等后发生了什么。

I also need to keep track of the locations "from/to" and the name of file. 我还需要跟踪“从/到”的位置和文件名。

Is there some alternative to the FileSystemWatcher that can distinguish between these actions? 除了FileSystemWatcher ,还有其他方法可以区分这些操作吗?

I think the FileSystemWatcher would be of use in this scenario. 我认为FileSystemWatcher将在这种情况下使用。 You could use the Changed event, which occurs when a file or directory is changed - like a copy/paste action. 您可以使用Changed事件,该事件在文件或目录更改时发生-例如复制/粘贴操作。

See the MSDN Documentation for this event, and the class itself. 有关此事件和类本身,请参见MSDN文档 Note that there are other events that you can also use for the delete/cut actions. 请注意,还有其他事件也可以用于删除/剪切操作。

The events use the FileSystemEventArgs which contains properties for FullPath and Name . 这些事件使用FileSystemEventArgs ,其中包含FullPathName属性。

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

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