Sign in to follow this  
Followers 0
grasshopper3

Dir Monitoring

1 post in this topic

Hey,

I am trying to monitor a dir for any .rar files. I am currently using something similar to what is below. Currently it only monitors that dir and no sub-dirs. I know if you monitor the root of the drive it will monitor all dirs on the drive, but is there a way to monitor only one dir and its sub-dirs? I realize that I can include the path that I want monitored in my IF Statement and monitor the root, but I feel that is only a work around for what I want. Does anyone have any ideas?

#include <Array.au3>
#include <FileSystemMonitor.au3>
Local $path = @ScriptDir & "\TestDir"
Global $MonitorArray[1][3], $MonitorCount = 0
; Setup File System Monitoring
_FileSysMonSetup(3, $Path, "")

; Main Loop
WHile 1

    ; Handle Directory related events
    _FileSysMonDirEventHandler()

WEnd


Func _FileSysMonActionEvent($event_type, $event_id, $event_value)

    Local $event_type_name
    Local $fs_event = ObjCreate("Scripting.Dictionary")

    Switch $event_type
        
        Case 0

            $fs_event.item(Hex(0x00000001)) = "file added to the directory"
            $fs_event.item(Hex(0x00000002)) = "file removed from the directory"
            $fs_event.item(Hex(0x00000003)) = "file was modified"
            $fs_event.item(Hex(0x00000004)) = "file was renamed old name"
            $fs_event.item(Hex(0x00000005)) = "file was renamed new name"

    EndSwitch
    
    if StringLen($fs_event.item(Hex($event_id))) > 0 Then
    
        $event_type_name = $fs_event.item(Hex($event_id))
        
        If StringInStr($event_value,".rar") And $event_type_name = "file added to the directory" Then
            FileWrite(@ScriptDir & '\Resources\UnRAR\UnRAR.log','"' & @ScriptDir & '\Resources\UnRAR\UnRAR.exe" x "' & $event_value & '" "' & @ScriptDir&'\CompleteDownloads\' & $event_value & '"' & @CRLF)
        EndIf
    
    EndIf
EndFunc

Share this post


Link to post
Share on other sites



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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0