MarceloP Posted December 4, 2008 Posted December 4, 2008 Hi everyone, I wrote two programs with AutoIt, one of them runs silently and synchronizes a directory between two computers, after a series of checks. It then writes some log lines to a text log file. I'm wondering if anyone has an idea on how to limit this log file size, I mean, discarding the oldest lines after some pre-determined file size, so the log file does not grow very much. I'm a little rusty on my programming skills, hehehh... Would appreciate any directions. Thanks, MarceloP
Robjong Posted December 4, 2008 Posted December 4, 2008 Hey, I got a func for exactly this (ill see if i can dig it up), but you should look at FileGetSize, and then FileDelete and/or FileMove(). If the filesize is more then the the max size just delete or move the file Rob
yxrkt Posted December 4, 2008 Posted December 4, 2008 expandcollapse popup$maxlines = 120 $file = @scriptdir&"/test.txt" toolong($file,$maxlines) func toolong($filei,$maxlines) if lines($filei) > $maxlines then $a = filetoarray($filei) $file = FileOpen($filei, 2) for $i = $a[0]-$maxlines to $a[0] FileWriteLine($filei,$a[$i] & @crlf) next FileClose($filei) endif endfunc func filetoarray($file) $count = lines($file) dim $ar[$count+1] $ar[0]=$count $file = FileOpen($file, 0) $i = 1 While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $ar[$i] = $line $i += 1 Wend FileClose($file) return $ar EndFunc func lines($file) $file = FileOpen($file, 0) $i = 0 While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $i += 1 Wend FileClose($file) return $i endfunc
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