Jump to content

monitor dir for added files and after adding file delete after soem time


Go to solution Solved by Melba23,

Recommended Posts

 thnx melba for the reply,

I just looked in to it and your explanation does sounds and seems logical now that you say it.

but how to build a "2D" array and get stuff from a list...  :huh2:

i realy love autoit :thumbsup: but i'm not quit handy whit it....

could you explain some more in little more simple words :D

as finishing touch god created the dutch

Link to comment
Share on other sites

  • Moderators

FMS,

It is easier to code it and show you: ;)

#include "FileSystemMonitor.au3"
#include <Date.au3>
#include <Array.au3>

Global $aFileData[1][2] = [[0, 0]] ; Declare 2D array with a count in the [0][0] element
Global $sPath = "C:\1"

_FileSysMonSetup(1, $sPath)

AdlibRegister("_checkFile", 10000)

While 1
    _FileSysMonDirEventHandler()
    Sleep(10)
WEnd

Func _FileSysMonActionEvent($event_type, $event_id, $event_value)
    Switch $event_type
        Case 0
            Switch $event_id
                Case 1
                    ; Add file to array
                    $aFileData[0][0] += 1    ; Increase count
                    ; ReDim the array
                    ReDim $aFileData[$aFileData[0][0] + 1][UBound($aFileData, 2)]
                    ; Add data for this file
                    $aFileData[$aFileData[0][0]][0] = $event_value ; Only save the filename
                    $aTime = FileGetTime($aFileData[$aFileData[0][0]][0])
                    $aFileData[$aFileData[0][0]][1] = $aTime[0] & "/" & $aTime[1] & "/" & $aTime[2] & " " & $aTime[3] & ":" & $aTime[4] & ":" & $aTime[5]
                    ; Which means we need to add the path here
                    ConsoleWrite("Adding file: " & $sPath & "\" & $aFileData[$aFileData[0][0]][0] & " - " & $aFileData[$aFileData[0][0]][1] & @CRLF)
            EndSwitch
    EndSwitch
EndFunc

Func _checkFile()
    ; Loop through the array from the bottom up
    For $i = $aFileData[0][0] To 1 Step -1
        $iSecs = _DateDiff("s", $aFileData[$i][1], _NowCalc())
        If $iSecs > 20 Then
            ; Access the array element containing the filename
            ConsoleWrite("+Now copying: " & $sPath & "\" & $aFileData[$i][0] & " to" &  " C:\2\" & $aFileData[$i][0] & @CRLF)
            ; Remove the file from the array and reset the count
            $aFileData[0][0] -= 1
            _ArrayDelete($aFileData, $i)
        EndIf
    Next
    _ArrayDisplay($aFileData, "", Default, 8) ; Just for demo to show you the array
EndFunc
Does that make it clearer? Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I got a error code when i run this :(

$aFileData[$aFileData[0][0]][1] = $aTime[0] & "/" & $aTime[1] & "/" & $aTime[2] & " " & $aTime[3] & ":" & $aTime[4] & ":" & $aTime[5]
$aFileData[$aFileData[0][0]][1] = $aTime^ ERROR
>Exit code: 1    Time: 7.115

also i think because of this error the error display isn't working.... ( i think :))

I believe its :

 

$aFileData[$aFileData[0][0]][1] = $aTime[0] & "/" & $aTime[0][0]][1] & "/" & $aTime[0][0]][2] & " " & $aTime[0][0]][3] & ":" & $aTime[4] & ":" & $aTime[0][0]][5]

or am i wrong and don't understand it at all :)
 

Edited by FMS

as finishing touch god created the dutch

Link to comment
Share on other sites

  • Moderators

FMS,

I do not get that error. What is the line above the 3 you posted? If (as I suspect) it is "Subscript used on non-accessible variable" then it means that you are not reading the file time correctly. :(

Let us try something a bit different - change the code to this:

$aFileData[$aFileData[0][0]][0] = $event_value ; Only save the filename
$aFileData[$aFileData[0][0]][1] = _NowCalc() ; Just set current time <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Which means we need to add the path here
That avoids FileGetTime altogether. :)

And as to your suggested fix:

i wrong and don't understand it at all

is correct. FileGetTime returns a 1D array, so there is absolutely no point in using 2D syntax. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

NICE NICE NICE THNX MELBA!!!!! :thumbsup:

this works like a charm.......

also it makes me a little bit better in autoit :)

thnx for the explanation....

(also the arraydisplay function... i will use this a LOT more in the futher..... )
(din't know this was possible :))

 

ps. indeed it was givin me the responce :  "Subscript used on non-accessible variable"

Edited by FMS

as finishing touch god created the dutch

Link to comment
Share on other sites

  • Moderators

FMS,

Glad I could help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...