ame1011 Posted November 8, 2008 Posted November 8, 2008 Hi there, I was wondering if there is a special event that is thrown when the contents of a folder change so that my script can preform an action every time this happens? I want to have a small portion of my script run in the taskbar 24/7 and monitor a certain folder, if files are added or taken away or renamed it should update my database that stores all of these files. If there is no event, what is the best way to accomplish this? Just do a dir on the folder every so often? Thanks in advance [font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Valuater Posted November 8, 2008 Posted November 8, 2008 Just place something like this ion a loop $timer = TimerInit() $size = DirGetSize(@ScriptDir,1) $diff = Round(TimerDiff($timer) / 1000) ; time in seconds If IsArray($size) Then Msgbox(0,"DirGetSize-Info","Size(Bytes):" & $size[0] & @LF _ & "Files:" & $size[1] & @LF & "Dirs:" & $size[2] & @LF _ & "TimeDiff(Sec):" & $diff) EndIf 8)
Paulchen Posted November 9, 2008 Posted November 9, 2008 You can use WMI with __InstanceCreationEvent.Here a sample that based on #337058expandcollapse popup;~ WMI monitoring Dim $strQuery, $SINK, $objContext, $objWMIService Dim $Eventtime= 2 ;Create Object Sink_Start($sink) ;~ Set Sink _find_folders("C:\Temp") func _find_folders($path,$subtree=False) $monitordrive = stringleft($path,2) $monitorpath = StringReplace(stringtrimleft($path,2),"\","\\") & "\\" SINK_Add($monitordrive,$monitorpath,$sink) ConsoleWrite($path & @crlf) if $subtree=false then Return local $first=FileFindFirstFile($path & "\*.*") while 1 $fichier = FileFindNextFile($first) if @error then ExitLoop if stringinstr(FileGetAttrib($path & "\" & $fichier),"D") then _find_folders($path & "\" & $fichier) WEnd EndFunc While 1 Sleep(200) WEnd func Sink_Start(byref $Sink) $SINK = ObjCreate("WbemScripting.SWbemSink") ObjEvent($SINK, "SINK_") EndFunc func SINK_Add($wmidrive,$wmipath,$sinkref) $objContext = ObjCreate("WbemScripting.SWbemNamedValueSet") $strQuery = "SELECT * FROM __InstanceOperationEvent WITHIN " & $Eventtime & " WHERE TargetInstance ISA 'CIM_DataFile' and TargetInstance.Path = '" & $wmipath & "' and TargetInstance.drive = '" & $wmidrive & "'" $objWMIService = ObjGet("winmgmts:!\\.\root\cimv2") $objWMIService.ExecNotificationQueryAsync ($sinkref,$strQuery, Default, Default, Default, $objContext) EndFunc ;****************************************************************************** Func SINK_OnObjectReady ($objLatestEvent, $objAsyncContext) ;Trap asynchronous events. ;$objAsyncContextItem = $objAsyncContext.Item ("hostname") $filename= $objLatestEvent.TargetInstance.Properties_.item("Name").value ConsoleWrite($filename & @CRLF) EndFunc ;==>SINK_OnObjectReady
rover Posted November 9, 2008 Posted November 9, 2008 Hi there, I was wondering if there is a special event that is thrown when the contents of a folder change so that my script can preform an action every time this happens?I want to have a small portion of my script run in the taskbar 24/7 and monitor a certain folder, if files are added or taken away or renamed it should update my database that stores all of these files. If there is no event, what is the best way to accomplish this? Just do a dir on the folder every so often?Thanks in advance@ame1011have a look at this folder monitoring scripta (broken) monitor file changes script which uses ReadDirectoryChangeWhttp://www.autoitscript.com/forum/index.php?showtopic=69044 I see fascists...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now