vb.net – FileSystemWatcher – 没有API不能这样做?

我想看看几个文件夹是否正在接收新文件,然后处理它.这工作正常,我已经声明了FileSystemWatcher并设置了EventHandler.

现在,一切正常,如果我在那里创建一个新文件,它会注意到它.

然后,我注意到当我粘贴文件时,它没有注意到它.我已经在谷歌上搜索了,我读到目前为止内置的FileSystemWatcher是不可能的.
所以我想到API来管理这个,但我实际上不知道如何处理它或从哪里开始.这个程序是一个工作,所以我真的需要它.
我感谢任何帮助,链接或其他事情来处理.

谢谢!如果事情不明确,请避免Downvote并问我;)

最佳答案 以下工作按预期完成(.net v4.5).粘贴到目录中会触发Change事件.

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim fw As New FileSystemWatcher
    fw.Path = "c:\Temp"
    fw.Filter = "*.*"
    fw.IncludeSubdirectories = False

    AddHandler fw.Created, New FileSystemEventHandler(AddressOf FileWatcherFileChange)
    AddHandler fw.Deleted, New FileSystemEventHandler(AddressOf FileWatcherFileDeleted)
    AddHandler fw.Renamed, New RenamedEventHandler(AddressOf FileWatcherFileRenamed)
    AddHandler fw.Error, New ErrorEventHandler(AddressOf FileWatcherError)

    fw.EnableRaisingEvents = True

End Sub

Private Sub FileWatcherFileChange(ByVal source As Object, ByVal e As FileSystemEventArgs)

    MsgBox("Change")

End Sub

Private Sub FileWatcherFileDeleted(ByVal source As Object, ByVal e As FileSystemEventArgs)

    MsgBox("Deleted")

End Sub

Private Sub FileWatcherFileRenamed(ByVal source As Object, ByVal e As FileSystemEventArgs)

    MsgBox("Renamed")

End Sub

Private Sub FileWatcherError(ByVal source As Object, ByVal e As System.IO.ErrorEventArgs)

    MsgBox("Error")

End Sub 

结束班

点赞