erezlevi Posted May 22, 2008 Posted May 22, 2008 hi, I need help in deleting files. files are called this way: reg_YYYYMMDDHHMMSS.txt I need to delete files every 6 hours - the past 5 hours should be deleted. I thougth of two options, to convert the numbers: HHMMSS to 21600 (every 6 hours: 6*60*60), but that will only give me a solution on when to delete the files....but not the algorithem to delete the ones with HH lower then the current hour. if the hour now is 23,files with hours: 22,21,20,19,18 needs to be deleted. my problem is with the 24 clock. 000000 is midnigth I can't use (-) here because i will get a negetive values. pls advise me. THanks,
Developers Jos Posted May 22, 2008 Developers Posted May 22, 2008 The _DateDiff() UDF should help you to calculate the time passed. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
weaponx Posted May 22, 2008 Posted May 22, 2008 #include <date.au3> $filename = "reg_YYYYMMDDHHMMSS.txt" $YYYY = StringMid($filename, 5,4) $MM = StringMid($filename, 9,2) $DD = StringMid($filename, 11,2) $HH = StringMid($filename, 13,2) $MM = StringMid($filename, 15,2) $SS = StringMid($filename, 17,2) $formatted = StringFormat("%s/%s/%s %s:%s:%s",$YYYY,$MM,$DD,$HH,$MM,$SS) ConsoleWrite($formatted) If _DateDiff('h', $formatted, _NowCalc) > 5 ;FileDelete($filename) EndIf
erezlevi Posted May 22, 2008 Author Posted May 22, 2008 ok, you gave me a solution on how to know when 6 hours have passed. but what do I do when the time is 01:07:30 and the file names are: 010730.txt 010729.txt ..... 000030.txt .... 231000.txt 230000.txt how do I tell it to del 5 hours before 01:00:00 at night. I can solved this by doing "IF" statments, like : expandcollapse popup if $H=01 then $H1=20 $H2=21 $H3=22 $H4=23 $H5=24 filedelete ("c:\$H1*") filedelete ("c:\$H2*") filedelete ("c:\$H3*") .... else if $H=00 then $H1=19 $H2=21 ... I think you got my point now.... martin Posted May 22, 2008 martin MVPs 7.1k 3 ~~\o/~~~/0\=¬''~~~ Posted May 22, 2008 (edited) ok, you gave me a solution on how to know when 6 hours have passed. but what do I do when the time is 01:07:30 and the file names are: 010730.txt 010729.txt ..... 000030.txt .... 231000.txt 230000.txt how do I tell it to del 5 hours before 01:00:00 at night. I can solved this by doing "IF" statments, like : if $H=01 then $H1=20 $H2=21 $H3=22 $H4=23 $H5=24 filedelete ("c:\$H1*") filedelete ("c:\$H2*") filedelete ("c:\$H3*") .... else if $H=00 then $H1=19 $H2=21 ... I think you got my point now.... Couldn't you say $H1 = $H0 - 5 If $H1 < 0 then $H1 += 24 Edited May 22, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
erezlevi Posted May 22, 2008 Author Posted May 22, 2008 Couldn't you say $H1 = $H0 - 5 If $H1 < 0 then $H1 += 24 Thanks martin. it is the hour here.... 01:08 AM... I need more coffee.....
Recommended Posts
erezlevi