Justmobile Posted November 3, 2004 Share Posted November 3, 2004 Hi all, Question, is it possible to do some action if an given file has been changed (file size), this mean i give the info from the file tst.txt and do an check serveral times on the contents or size of the file if there is any change i need to do a new action. But the tracker is, do i need make a loop that will check every xx sec. to that file or is there an nicer way for it. I hope someone has a solution. thanks justmobile Link to comment Share on other sites More sharing options...
ezzetabi Posted November 3, 2004 Share Posted November 3, 2004 Nicer? What do you mean? $sFile = 'Filename here' $iTime = 60 ;in seconds Do $old = FileGetSize($sFile) Sleep($iTime * 1000) $new = FileGetSize($sFile) If $new <> $old Then ExitLoop Until 0 MsgBox(0,'','Changed') Link to comment Share on other sites More sharing options...
Developers Jos Posted November 3, 2004 Developers Share Posted November 3, 2004 (edited) ezzetabi, think you made a logic error ...... Should take the $old out of the loop..... $sFile = 'Filename here' $iTime = 60;in seconds $old = FileGetSize($sFile) Do Sleep($iTime * 1000) $new = FileGetSize($sFile) If $new <> $old Then ExitLoop Until 0 MsgBox(0,'','Changed') EDIT: Thinking again: your version should work too.. Edited November 3, 2004 by JdeB 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. Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted November 3, 2004 Share Posted November 3, 2004 (edited) Try this (untested): Dim $fileCheck = "C:\CheckFile.txt"; This is the file being checked Dim $fileSize; This is the file size to check against (in Kb) Dim $secCheck = 30; This is the time increment to check the file Dim $lastCheck; This is the last time the file was checked $fileSize = FileGetSize( $fileCheck ) $lastCheck = TimerInit() $secCheck = $secCheck * 1000 While 1 If( TimerDiff( $lastCheck ) >= $secCheck ) Then If FileChange( $fileCheck, $fileSize ) Then ; Do something here if the size is the same Else ; Do something here if the file size changed EndIf $lastCheck = TimerInit() EndIf Sleep(10) Wend Func FileChange( $file, $size ) Return (FileGetSize($file) = $size) EndFunc You may also want to add a hot key to close it, but that is a general proof of concept, hope it helps. *** Matt @ MPCS EDIT: And of cource I am late again. Edited November 3, 2004 by Matt @ MPCS Link to comment Share on other sites More sharing options...
ezzetabi Posted November 3, 2004 Share Posted November 3, 2004 In fact it is the same if you leave the loop. But my 'edition' will be easier to use if you want just call a func when you find that size changed. You do the func, the size is reload in $old and after the wait checked again... Link to comment Share on other sites More sharing options...
Justmobile Posted November 3, 2004 Author Share Posted November 3, 2004 (edited) Cool guys, Yes i will try it all , it seems only the TimerInit(), is unknow for me... i have created this easy way: $size = FileGetSize("tekst.txt") While 1 $size1 = FileGetSize("tekst.txt") if $size <> $size1 Then $size = FileGetSize("tekst.txt") msgbox(0,"",$size) EndIf Wend Low solution but the script keeps on running while the file has been changed. cheers Justmobile ps. by example i have give the possible solution to say do i need check every xx sec. but this isn't necessary. Sorry for the misunderstanding in this. Edited November 3, 2004 by Justmobile Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted November 3, 2004 Share Posted November 3, 2004 You could keep the script you have and if you want it to leave the loop if the file is the same, just throw in an ExitLoop. You should also throw in a Sleep() so your don't overload your processor. This will keep it from eating all your system resources. Hope this helps! *** Matt @ MPCS Link to comment Share on other sites More sharing options...
Justmobile Posted November 3, 2004 Author Share Posted November 3, 2004 yep that's the new issue, to prevent overload and looping arround , other way's other that looping?. i need serveral file's to check and if one of those wil changed the script must do the action to add al the contents of the given file to one new file. thats the case .. cheers justmobile Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted November 3, 2004 Share Posted November 3, 2004 I know that with my code example provided above, you can do what you are looking for. To support multiple files I would look at using either a text file or an INI configuration file. Looping through the file and checking would just go into the master loop. This would be a reletivly simple task to accomplish. *** Matt @ MPCS Link to comment Share on other sites More sharing options...
ezzetabi Posted November 3, 2004 Share Posted November 3, 2004 No. No other way. If you want make an action more than once you need looping! Link to comment Share on other sites More sharing options...
Justmobile Posted November 3, 2004 Author Share Posted November 3, 2004 what about funtion TimerInit()?, with the compiler i use (beta with gui support) it don't reconise so do i cheers Justmobile Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted November 3, 2004 Share Posted November 3, 2004 TimerInit does exist in 103... here is the 102 docs for it:http://www.autoitscript.com/autoit3/docs/f...s/TimerInit.htm*** Matt @ MPCS Link to comment Share on other sites More sharing options...
Justmobile Posted November 3, 2004 Author Share Posted November 3, 2004 thanks, updated!.. it works.. cheers Justmobile 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