beqa Posted June 18, 2014 Posted June 18, 2014 hello all. i need script for the server to monitor directory for the fles if i add file to this dir it must delete this file after some period. please help me.
Moderators Melba23 Posted June 18, 2014 Moderators Posted June 18, 2014 beqa,I have used the FileSystemMonitor UDF to detect new files being added to a folder - knowing which file was added will enable you to delete it after a specified delay. Give it a try and see how you get on. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
beqa Posted June 18, 2014 Author Posted June 18, 2014 (edited) this is what i understood from this udf #include <FileSystemMonitor.au3> _FileSysMonSetup(1, "C:\", "") While 1 _FileSysMonDirEventHandler() _FileSysMonSetDirMonPath("C:\1") 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|FILE_ACTION_ADDED" beep(100,1000) $fs_event.item(Hex(0x00000002)) = "file removed from the directory|FILE_ACTION_REMOVED" beep(200,2000) $fs_event.item(Hex(0x00000003)) = "file was modified|FILE_ACTION_MODIFIED" $fs_event.item(Hex(0x00000004)) = "file was renamed old name|FILE_ACTION_RENAMED_OLD_NAME" $fs_event.item(Hex(0x00000005)) = "file was renamed new name|FILE_ACTION_RENAMED_NEW_NAME" EndSwitch Edited June 18, 2014 by Melba23 Added code tags
beqa Posted June 18, 2014 Author Posted June 18, 2014 as i understand now i need a loop in which beep in the future deleting files will perform on checking. how i can do it
Moderators Melba23 Posted June 18, 2014 Moderators Posted June 18, 2014 beqa,This thread gives much more detail on how to use the UDF and contains a couple of scripts where I rewrote the UDF and example to make them a bit clearer - I hope it will explain things a little better. M23.P.S. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
beqa Posted June 18, 2014 Author Posted June 18, 2014 (edited) hi. please lookat this code and tell if something is wrong.#include <filesysmon.au3> _FileSysMonSetup(1, "C:\1") While 1 _FileSysMonDirEventHandler() WEnd Func _FileSysMonActionEvent($event_type, $event_id, $event_value) msgbox(0, $event_type & " - " & $event_id & " - " & $event_value, "test") EndFunc Edited June 18, 2014 by Melba23 Added code tags
Moderators Melba23 Posted June 18, 2014 Moderators Posted June 18, 2014 beqa,Looks fine to me. If you only want to know when a file has been added to the folder you can do something like this: Func _FileSysMonActionEvent($event_type, $event_id, $event_value) Switch $event_type Case 0 ; Folder event Switch $event_id Case 1 ; File added MsgBox(0, "File Added", $event_value & " was added to the folder") EndSwitch EndSwitch EndFuncAll good now? M23P.S. Please use code tags as I suggested earlier. 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
beqa Posted June 18, 2014 Author Posted June 18, 2014 great, thanks, now only thing left to record file adding date and then delete it after some period.
Moderators Melba23 Posted June 18, 2014 Moderators Posted June 18, 2014 beqa,FileGetTime, _DateDiff & FileDelete should be able to help you there. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
beqa Posted June 18, 2014 Author Posted June 18, 2014 as, i understood i should write filename filedate in the file, and check it. am i right?
Moderators Melba23 Posted June 18, 2014 Moderators Posted June 18, 2014 beqa,I would store the file name and creation time within the script and check the time elapsed since creation every so often - an Adlib function might be a good way to do this. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
beqa Posted June 18, 2014 Author Posted June 18, 2014 (edited) please if you can look at this code.#include <filesysmon.au3> #include <Date.au3> _FileSysMonSetup(1, "C:\1") While 1 _FileSysMonDirEventHandler() WEnd Func _FileSysMonActionEvent($event_type, $event_id, $event_value) Switch $event_type Case 0 ; Folder event Switch $event_id Case 1 ; File added _checkFile() AdlibRegister("_checkFile", 10000) EndSwitch EndSwitch EndFunc Func _checkFile($event_value) If _IsFileOlder($event_value, 10) Then MsgBox(4096, '', 'File is older than 10 days.') Else MsgBox(4096, '', 'File isn''t older than 10 days.') EndIf EndFunc Func _IsFileOlder($event_value, $iDays) Local $aArray = FileGetTime($event_value, 0) Return _DateDiff('D', $aArray[0] & '/' & $aArray[1] & '/' & $aArray[2] & ' ' & $aArray[3] & ':' & $aArray[4] & ':' & $aArray[5], @YEAR & '/' & @MON & '/' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC) >= $iDays EndFunc on line 15 there is an error as i understood i mustcall event_value parameter, but i don't know how. Edited June 18, 2014 by Melba23 Added code tags
beqa Posted June 18, 2014 Author Posted June 18, 2014 oh, it is whole incorrect code. can i use variables of _FileSysMonActionEvent into other functions.
Moderators Solution Melba23 Posted June 18, 2014 Moderators Solution Posted June 18, 2014 beqa,I would do it like this: expandcollapse popup#include "FileSystemMonitor_Mod.au3" #include <Date.au3> Global $aFileData[2] Global $sPath = "C:\1" _FileSysMonSetup(1, $sPath) AdlibRegister("_checkFile", 10000) While 1 _FileSysMonDirEventHandler() Sleep(10) ; Important so as not to fry the CPU <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< WEnd Func _FileSysMonActionEvent($event_type, $event_id, $event_value) Switch $event_type Case 0 ; Folder event Switch $event_id Case 1 ; File added ; Save the data $aFileData[0] = $sPath & "\" & $event_value $aTime = FileGetTime($aFileData[0]) $aFileData[1] = $aTime[0] & "/" & $aTime[1] & "/" & $aTime[2] & " " & $aTime[3] & ":" & $aTime[4] & ":" & $aTime[5] ConsoleWrite($aFileData[0] & " - " & $aFileData[1] & @CRLF) ; Just so you can see what is stored EndSwitch EndSwitch EndFunc ;==>_FileSysMonActionEvent Func _checkFile() ; Check a file has been saved If $aFileData[0] Then ; Get seconds since creation $iSecs = _DateDiff("s", $aFileData[1], _NowCalc()) If $iSecs > 120 Then ConsoleWrite("File is over 2 mins old" & @CRLF) ; Clear array ready for next file Global $aFileData[2] Else ConsoleWrite("File is " & $iSecs & " secs old" & @CRLF) EndIf EndIf EndFunc ;==>_checkFilePlease ask if you have any questions. M23P.S. And if you post any more code without using the code tags I will stop helping (use the link in post #5 to see how to do it). 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
beqa Posted June 18, 2014 Author Posted June 18, 2014 (edited) thanks a lot for help. it worksexpandcollapse popup#include <filesysmon.au3> #include <Date.au3> Global $aFileData[2] Global $sPath = "C:\1" _FileSysMonSetup(1, $sPath) AdlibRegister("_checkFile", 3600000) While 1 _FileSysMonDirEventHandler() Sleep(10) WEnd Func _FileSysMonActionEvent($event_type, $event_id, $event_value) Switch $event_type Case 0 ; Folder event Switch $event_id Case 1 ; File added $aFileData[0] = $sPath & "\" & $event_value $aTime = FileGetTime($aFileData[0]) $aFileData[1] = $aTime[0] & "/" & $aTime[1] & "/" & $aTime[2] & " " & $aTime[3] & ":" & $aTime[4] & ":" & $aTime[5] EndSwitch EndSwitch EndFunc;==>_FileSysMonActionEvent Func _checkFile() If $aFileData[0] Then $iDays = _DateDiff("d", $aFileData[1], _NowCalc()) If $iDays > 10 Then FileDelete($aFileData[0]) Global $aFileData[2] Else msgbox(0, "test", "File is " & $iDays & " secs old" & @CRLF) EndIf EndIf EndFunc;==>_checkFilenow i will fetch variable values from .configuration file Edited June 18, 2014 by Melba23 Added code tags - for the final time!
Moderators Melba23 Posted June 18, 2014 Moderators Posted June 18, 2014 beqa,Delighted I could help. But I have a question in return. You obviously understand English - so why are you ignoring my requests to use code tags when you post code? Using the tags makes for a much more pleasant reading experience for other forum users - as you can see above in the many posts where I have added them - which is why we encourage their use. So in future please do use them - or I will begin to get annoyed. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
beqa Posted June 18, 2014 Author Posted June 18, 2014 this forum's wicivic editor isn't accessible for screenreaders and i can't find it always.
Moderators Melba23 Posted June 18, 2014 Moderators Posted June 18, 2014 beqa,Then please add the following before and after the code you post: [code=autoit:0] Your code goes here [/code]M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
FMS Posted June 24, 2014 Posted June 24, 2014 (edited) nice script Melba, Just what i was looking for.... but just to clearify.. I tweaked it a little bit because i want to use it for monitoring a directory and get the new file and put it somewhere else.. expandcollapse popup#include "FileSystemMonitor.au3" #include <Date.au3> Global $aFileData[2] 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 $aFileData[0] = $sPath & "\" & $event_value $aTime = FileGetTime($aFileData[0]) $aFileData[1] = $aTime[0] & "/" & $aTime[1] & "/" & $aTime[2] & " " & $aTime[3] & ":" & $aTime[4] & ":" & $aTime[5] ConsoleWrite($aFileData[0] & " - " & $aFileData[1] & @CRLF) EndSwitch EndSwitch EndFunc Func _checkFile() If $aFileData[0] Then $iSecs = _DateDiff("s", $aFileData[1], _NowCalc()) If $iSecs > 120 Then ConsoleWrite("File is over 2 mins old" & @CRLF) FileCopy( $sPath & "\" $aFileData,"C:\2\"& $aFileData,8); <<<< Global $aFileData[2] Else ConsoleWrite("File is " & $iSecs & " secs old" & @CRLF) EndIf EndIf EndFunc Iff i use filecopy $aFileData it gets the whole directory and i want just that file.... And iff there are more new files instead of only 1 new file I also want to copy them.... Could u help me whit that? maybe i missed something.... thnx in advanced Edited June 24, 2014 by FMS as finishing touch god created the dutch
Moderators Melba23 Posted June 24, 2014 Moderators Posted June 24, 2014 FMS,The file name and time are stored in an array - to access them you need to use the correct index. At present you are using just the array name in your FileCopy line, which returns a blank value and so the string is just the path. Try this code:expandcollapse popup#include "FileSystemMonitor.au3" #include <Date.au3> Global $aFileData[2] 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 $aFileData[0] = $event_value ; Only save the filename <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $aTime = FileGetTime($aFileData[0]) $aFileData[1] = $aTime[0] & "/" & $aTime[1] & "/" & $aTime[2] & " " & $aTime[3] & ":" & $aTime[4] & ":" & $aTime[5] ; Which means we need to add the path here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite($spath & "\" & $aFileData[0] & " - " & $aFileData[1] & @CRLF) EndSwitch EndSwitch EndFunc Func _checkFile() If $aFileData[0] Then $iSecs = _DateDiff("s", $aFileData[1], _NowCalc()) If $iSecs > 120 Then ConsoleWrite("File is over 2 mins old" & @CRLF) ; Access the array element containing the filename <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< FileCopy($sPath & "\" & $aFileData[0], "C:\2\" & $aFileData[0], 8) Global $aFileData[2] Else ConsoleWrite("File is " & $iSecs & " secs old" & @CRLF) EndIf EndIf EndFuncThat works for me. As for dealing with several files, you would need to declare the $aFileData array as a 2D array and then add each newly created file to the list, removing it once it had been copied. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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