主题:[讨论]如何实现系统操作的监控。如文件的复制、删除等
Komno
[专家分:0] 发布于 2006-10-20 10:08:00
用vb.net如何实现系统操作的监控。如文件的复制、删除等
回复列表 (共2个回复)
沙发
pulai [专家分:0] 发布于 2006-10-31 05:35:00
拉圾
想发个源码 mmd 限制10000字以内 烦人
板凳
anlige [专家分:270] 发布于 2007-02-26 02:05:00
下面的代码:fsw为"FileSystemWatcher"控件
fbd为FolderBrowserDialog控件
ofd为 OpenFileDialog控件
Public Class main
Dim i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
fsw.EnableRaisingEvents = True
fsw.Path = TextBox2.Text
TextBox1.Text = "开始监视路径" & TextBox2.Text & "..." & vbCrLf
Button4.Enabled = False
TextBox2.Enabled = Button4.Enabled
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "Error")
End Try
End Sub
Private Sub fsw_Created(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles fsw.Created
TextBox1.Text = TextBox1.Text & i & ":创建'" & e.FullPath & "'" & vbCrLf
i = i + 1
End Sub
Private Sub fsw_Deleted(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles fsw.Deleted
TextBox1.Text = TextBox1.Text & i & ":删除'" & e.FullPath & "'" & vbCrLf
i = i + 1
End Sub
Private Sub fsw_Renamed(ByVal sender As System.Object, ByVal e As System.IO.RenamedEventArgs) Handles fsw.Renamed
TextBox1.Text = TextBox1.Text & i & ":重命名'" & e.OldFullPath & "'为'" & e.FullPath & "'" & vbCrLf
i = i + 1
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
i = 1
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button4.Enabled = True
TextBox2.Enabled = Button4.Enabled
fsw.EnableRaisingEvents = False
TextBox1.Text = TextBox1.Text + "已经停止监视!"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
i = 1
TextBox1.Text = ""
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If fbd.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox2.Text = fbd.SelectedPath
End If
End Sub
End Class
我来回复