KickStarter15 Posted September 4, 2017 Share Posted September 4, 2017 Hi Experts, I just need your help with the counting for Sleep() to count 10 days and then do the FileDelete(). Also, I need this little code to running 24/7 in a server. #include <Date.au3> #include <File.au3> Sleep(60000) ;60 for 1 minute is this correct? $sFldr2 = "D:\Programs\Test\Temp\" FileDelete($sFldr2 & "*.*") Local $File = FileOpen("D:\Programs\Test\Temp.log", 1) FileWriteLine($File, '"Deleted files in Temp folder" ' & "on " & _DateTimeFormat(_NowCalc(), 2) &" at "& _NowTime()) FileClose($File) I got confused with it and little bit hanging on how to run it 24/7. Also, if you have any better way to do it, then, that would be great. Thanks, Expert in advance. KS15 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 4, 2017 Moderators Share Posted September 4, 2017 11 KickStarter15, I would use _DateDiff rather than Sleep - something like this (untested): expandcollapse popup#include <File.au3> #include <Date.au3> ; Use a HotKey to exit if necessary HotKeySet("{ESC}", "_Exit") $sFldr2 = "D:\Programs\Test\Temp\" ; Set values for today's date $sDay = @MDAY $sFormattedDate = _NowCalcDate() ; Start an infinte loop While 1 ; Check when day changes If $sDay <> @MDAY Then ; Reset stored day so we only check once a day $sDay = @MDAY ; Check if 10 days passed since last delete If _DateDiff("D", $sFormattedDate, _NowCalcDate()) > 10 Then ; If so then run the code FileDelete($sFldr2 & "*.*") Local $File = FileOpen("D:\Programs\Test\Temp.log", $FO_APPEND) FileWriteLine($File, '"Deleted files in Temp folder" ' & "on " & _DateTimeFormat(_NowCalc(), 2) &" at "& _NowTime()) FileClose($File) ; Reset the date so we wait for another 10 days $sFormattedDate = _NowCalcDate() EndIf EndIf WEnd Func _Exit() Exit EndFunc M23 KickStarter15 1 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 Link to comment Share on other sites More sharing options...
KickStarter15 Posted September 4, 2017 Author Share Posted September 4, 2017 @Melba23, Thanks, does this mean if I want to test it, like lets have it 1 day to see if its working. Should i modify the below: From If _DateDiff("D", $sFormattedDate, _NowCalcDate()) > 10 Then To If _DateDiff("D", $sFormattedDate, _NowCalcDate()) > 1 Then Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
AspirinJunkie Posted September 4, 2017 Share Posted September 4, 2017 Maybe it would be a better option if you use the task sheduler from windows. There you can define tasks which should run a program (your script) every period of a time. This should be more stable. Link to comment Share on other sites More sharing options...
KickStarter15 Posted September 5, 2017 Author Share Posted September 5, 2017 @AspirinJunkie, Thanks, but the code is for my other script and I will add this into that script. @Melba23, Is there a way that I can test your code using only minutes? I need to test this code first but i think its a per day count. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
KickStarter15 Posted September 5, 2017 Author Share Posted September 5, 2017 @Melba23, I got it. I tested it by doing below and it's working well. , thank you so much. #include <File.au3> #include <Date.au3> $sFormattedDate = "2017/08/25" ; I need to manaully input the date to get the greater sum of 10 in _DateDiff() If _DateDiff("D", $sFormattedDate, _NowCalcDate()) > 10 Then MsgBox(0,"","10 days already") Else MsgBox(0,"","Wait after 10 days") EndIf Exit Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
KickStarter15 Posted September 7, 2017 Author Share Posted September 7, 2017 @Melba23, Sorry for this but I need to ask something. When I ran my program with an infinite loop, my CPU usage increases rapidly (ranging from 60% to 88%) and what I did is I add sleep(10) function within the "While.." where the infinite loop starts. My question is, does this will affect the loop? however, the CPU usage was controlled with sleep(). Is this okay? While 1 ; Check when day changes If $sDay <> @MDAY Then ; Reset stored day so we only check once a day $sDay = @MDAY ; Check if 10 days passed since last delete Sleep(10) ; to slowdown the usage of my CPU If _DateDiff("D", $sFormattedDate, _NowCalcDate()) > 10 Then ; If so then run the code FileDelete($sFldr2 & "*.*") Local $File = FileOpen("D:\Programs\Test\Temp.log", $FO_APPEND) FileWriteLine($File, '"Deleted files in Temp folder" ' & "on " & _DateTimeFormat(_NowCalc(), 2) &" at "& _NowTime()) FileClose($File) ; Reset the date so we wait for another 10 days $sFormattedDate = _NowCalcDate() EndIf EndIf WEnd Thanks! KS15 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
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