Code: Alles auswählen
;Autor: jpfiste
EnableExplicit
Define EventID
#FILE_NOTIFY_CHANGE_FILE_NAME = 1
#FILE_NOTIFY_CHANGE_DIR_NAME = 2
#FILE_NOTIFY_CHANGE_ATTRIBUTES = 4
#FILE_NOTIFY_CHANGE_SIZE = 8
#FILE_NOTIFY_CHANGE_LAST_WRITE = $10
#FILE_NOTIFY_CHANGE_LAST_ACCESS = $20
#FILE_NOTIFY_CHANGE_CREATION = $40
#FILE_NOTIFY_CHANGE_SECURITY = $100
#FILE_NOTIFY_CHANGE_ALL = $17F
#FILE_SHARE_DELETE = 4
#FILE_ACTION_ADDED = 1
#FILE_ACTION_REMOVED = 2
#FILE_ACTION_MODIFIED = 3
#FILE_ACTION_RENAMED_OLD_NAME = 4
#FILE_ACTION_RENAMED_NEW_NAME = 5
Structure FILE_NOTIFY_INFORMATION
NextEntryOffset.l
Action.l
FileNameLength.l
Filename.s{255}
EndStructure
Import "kernel32.lib"
ReadDirectoryChangesW(a, b, c, d, e, f, g, h)
EndImport
Global WatchPath$=GetTemporaryDirectory()
Procedure WatchDirOrFile(z)
Protected DirectoryName.s="C:\"
Protected NotifyFilter.l = #FILE_NOTIFY_CHANGE_ALL
Protected buffer.FILE_NOTIFY_INFORMATION, ovlp.OVERLAPPED
Protected FileAction_Filename.s
Protected hDir
Protected bytesRead
Protected path$
hDir = CreateFile_(DirectoryName, #FILE_LIST_DIRECTORY, #FILE_SHARE_READ | #FILE_SHARE_WRITE | #FILE_SHARE_DELETE, #Null, #OPEN_EXISTING, #FILE_FLAG_BACKUP_SEMANTICS, #Null)
While ReadDirectoryChangesW(hDir, @buffer, SizeOf(FILE_NOTIFY_INFORMATION), #True, NotifyFilter, bytesRead, ovlp, 0)
FileAction_Filename = PeekS(@buffer\Filename, -1, #PB_Unicode)
path$=GetPathPart(DirectoryName+FileAction_Filename)
If FindString(path$,WatchPath$)
Select buffer\Action
Case #FILE_ACTION_ADDED
AddGadgetItem(2,-1,"Added: " + DirectoryName.s + FileAction_Filename,0,0)
Case #FILE_ACTION_REMOVED
AddGadgetItem(2,-1,"Removed: " + DirectoryName.s + FileAction_Filename,0,0)
Case #FILE_ACTION_MODIFIED
AddGadgetItem(2,-1,"Modified: " + DirectoryName.s + FileAction_Filename,0,0)
Case #FILE_ACTION_RENAMED_OLD_NAME
;Dateiumbenennung: Alter Dateiname
Case #FILE_ACTION_RENAMED_NEW_NAME
;Dateiumbenennung: Neuer Dateiname
EndSelect
EndIf
buffer\Filename = ""
Wend
EndProcedure
Define Hidden = 0
If OpenWindow(0,0,0,500,400,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadget(1,10,10,WindowWidth(0),20,"Veränderungen auf "+WatchPath$+":",0)
EditorGadget(2,10,30,WindowWidth(0)-20,WindowHeight(0)-60,0)
ButtonGadget(3,10,WindowHeight(0)-25,WindowWidth(0)-20,20,"end")
CreateThread(@WatchDirOrFile(),0)
CreateImage(0,16,16)
AddSysTrayIcon(0, WindowID(0), ImageID(0))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Hidden!1 : HideWindow(0, Hidden)
Case #PB_Event_SysTray
Hidden!1 : HideWindow(0, Hidden)
Case #PB_Event_Gadget
Select EventGadget()
Case 3
End
EndSelect
EndSelect
ForEver
EndIf