Hallo zusammen,
es gibt in Visual Basic so eine ziemlich geniale Klasse FileSystemWatcher.
Damit kann man Datei Änderungen eines bestimmten Ordners überwachen, ohne immer wieder in einer Schleife den Ordner irgendwie lesen zu müssen.
Weiß jemand, ob man solche Klassen aus VB auch in Autoit verwenden kann?
hier der Code aus VB
Code
Imports System.IO
Imports System.Diagnostics
Public Class Form1
Private Declare Function GetPrivateProfileStringA Lib "kernel32.dll" (ByVal lpSection As String, ByVal lpSetting As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public watchfolder As FileSystemWatcher
Private Sub logchange(ByVal source As Object, ByVal e As _
System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Changed Then
txt_folderactivity.Text &= "File " & e.FullPath & _
" has been modified" & vbCrLf
End If
If e.ChangeType = IO.WatcherChangeTypes.Created Then
txt_folderactivity.Text &= "File " & e.FullPath & _
" has been created" & vbCrLf
Shell("notepad.exe " & e.FullPath)
End If
If e.ChangeType = IO.WatcherChangeTypes.Deleted Then
txt_folderactivity.Text &= "File " & e.FullPath & _
" has been deleted" & vbCrLf
End If
End Sub
Public Sub logrename(ByVal source As Object, ByVal e As _
System.IO.RenamedEventArgs)
txt_folderactivity.Text &= "File" & e.OldName & _
" has been renamed to " & e.Name & vbCrLf
End Sub
Private Sub btn_stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_stop.Click
watchfolder.EnableRaisingEvents = False
btn_stop.Enabled = False
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
watchfolder = New System.IO.FileSystemWatcher()
'this is the path we want to monitor
'watchfolder.Path = txt_watchpath.Text
watchfolder.Path = "c:\test"
txt_watchpath.Text = watchfolder.Path
'Add a list of Filter we want to specify
'make sure you use OR for each Filter as we need to
'all of those
watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
IO.NotifyFilters.FileName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
IO.NotifyFilters.Attributes
' add the handler to each event
AddHandler watchfolder.Changed, AddressOf logchange
AddHandler watchfolder.Created, AddressOf logchange
AddHandler watchfolder.Deleted, AddressOf logchange
' add the rename handler as the signature is different
AddHandler watchfolder.Renamed, AddressOf logrename
'Set this property to true to start watching
watchfolder.EnableRaisingEvents = True
btn_stop.Enabled = True
End Sub
End Class
Alles anzeigen