Jump to content

File Monitor


LizardLord
 Share

Recommended Posts

I made a small script to keep track of my Temp file, but i never finished it and probably never will, so that's why i am releasing it now.

The code is based almost entirely of functions, and some functions have parts of code that was going to be used, but never were.

It works, but has numerous bugs/glitches. Especially when it comes to the Tool Tips...

Maybe you guys will use it for something.

I am still fairly new at Programming in General, so if i made any retarded mistakes don't bash my head in.

#include <Array.au3>
Opt("TrayMenuMode", 1)
Dim $Array[1]
Global $ErrorCode, $oDir
$hExit = TrayCreateItem("Exit")
$hDir = TrayCreateItem("Choose Folder")
$FileExists = FileExists(@ScriptDir & "\List.ini")
If $FileExists - 1 Then
    $SetFolderRunning = 1
    _SetFolder()
Else
    $SetFolderRunning = 0
    _Monitor()
EndIf

Func _SetFolder()
    
    $oDir = FileSelectFolder("Choose A folder to monitor", "My Computer")
    If @error Then
        Exit
    EndIf
    IniWrite(@ScriptDir & "\List.ini", "EN-US", "Dir", $oDir)
    _SetINI(1)
EndFunc   ;==>_SetFolder

Func _SetINI($iRunCallMonitor)
    Local $hFirstFile, $oArrayString
    Dim $FilesArray[1]
    $hFirstFile = FileFindFirstFile($oDir & "\*.*")
    While 1
        $oNextFile = FileFindNextFile($hFirstFile)
        If @error Then
            FileClose($hFirstFile)
            ExitLoop
        EndIf
        _ArrayAdd($FilesArray, $oNextFile)
    WEnd
    $oArrayString = _ArrayToString($FilesArray)
    IniWrite(@ScriptDir & "\List.ini", "EN-US", "Files", $oArrayString)
    $SetFolderRunning = 0
    If $iRunCallMonitor = 1 Then _Monitor()
EndFunc   ;==>_SetINI

Func _Monitor()
    While 1
        Local $oReadDir, $oFiles, $String
        $oReadDir = IniRead(@ScriptDir & "\List.ini", "EN-US", "Dir", "1")
        If $oReadDir = 1 Then
            MsgBox(1, "Error", "Ini Read error: Could Not Read Directory Data" & @CRLF & "Please Delete the the INI file in the program Directory")
            Exit
        EndIf
        $oFiles = IniRead(@ScriptDir & "\List.ini", "EN-US", "Files", "1")
        If $oFiles = 1 Then
            MsgBox(1, "Error", "Ini Read error: Could Not Read Catelogued Files" & @CRLF & "Please Delete the the INI file in the program Directory")
            Exit
        EndIf
        $hFirstFileCheck = FileFindFirstFile($oReadDir & "\*.*")
        While 1
            $oSearchFile = FileFindNextFile($hFirstFileCheck)
            If @error Then
                FileClose($hFirstFileCheck)
                ExitLoop
            EndIf
            _TraySystem()
            Sleep(100)
            _ArrayAdd($Array, $oSearchFile)
        WEnd
        $String = _ArrayToString($Array)
        Dim $Array[1]
        If StringCompare($String, $oFiles) <> 0 Then
            _TrayPopup($oFiles, $String, $oReadDir)
        Else
        EndIf
    WEnd
EndFunc   ;==>_Monitor

Func _TraySystem()
    Switch TrayGetMsg()
        Case $hExit
            Exit
        Case $hDir
            _SetFolder()
    EndSwitch
EndFunc   ;==>_TraySystem

Func _TrayPopup($iINI, $iArray, $iDir)
    Local $oString, $ReplaceString, $oFilesWrite
    
    $oString = StringCompare($iINI, $iArray)
    If $oString = -1 Then
        TrayTip("File Monitor", "A File Has Been removed from " & $iDir, 2, 2)
        $oFilesList = IniWrite(@ScriptDir & "\List.ini", "EN-US", "Files", $iArray)
    Else
        $ReplaceString = StringReplace($iArray, $iINI, " ")
        TrayTip("File Monitor", "A File (" & $ReplaceString & ") Has Been Added to " & $iDir, 2, 2)
        $oFilesList = IniWrite(@ScriptDir & "\List.ini", "EN-US", "Files", $iArray)
    EndIf
EndFunc   ;==>_TrayPopup
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...