masvil Posted October 15, 2006 Share Posted October 15, 2006 I have to check if a file size not changes for 3 times. I'm trying to do it using FileGetSize in a loop but still without success. Any help? Link to comment Share on other sites More sharing options...
Helge Posted October 15, 2006 Share Posted October 15, 2006 You have to describe your problem a little better. You say you want to check it in a loop, but you don't say anything about why and when should it check. Without any more info it is hard to suggest how you can build it up, but something like this should be the basics. - Initial / match-point$filesize = FileGetSize("file.txt")oÝ÷ Ø(^rHr§çZºÚ"µÍY ÌÍÙ[Ú^H ÉÝÈ[QÙ]Ú^J ][ÝÙ[K ][ÝÊH[ Link to comment Share on other sites More sharing options...
MHz Posted October 15, 2006 Share Posted October 15, 2006 WMI can watch a file also. The code below will check the file every 5 minutes for change. $file = 'Path\to\file.exe' ; Setup WMI $sComputer = @ComputerName $oWMIService = ObjGet("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & $sComputer & "\root\cimv2") $colMonitoredEvents = $oWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceModificationEvent WITHIN 10 WHERE " _ & "TargetInstance ISA 'CIM_DataFile' AND " _ & "TargetInstance.Name='" & StringReplace($file, '\', '\\') & "'") While 1 ; Reset timer to zero $time = TimerInit() ; Monitor file for event $oLatestEvent = $colMonitoredEvents.NextEvent ; Output if event older then 5 minutes If TimerDiff($time) > (5 * 60000) Then ConsoleWrite('Time: ' & @HOUR & ':' & @MIN & ':' & @SEC & @CRLF) ConsoleWrite("File: " & $oLatestEvent.TargetInstance.Name & @CRLF) ConsoleWrite("New size: " & $oLatestEvent.TargetInstance.FileSize & @CRLF) ConsoleWrite("Old size: " & $oLatestEvent.PreviousInstance.FileSize & @CRLF) EndIf WEnd Link to comment Share on other sites More sharing options...
masvil Posted October 15, 2006 Author Share Posted October 15, 2006 (edited) You have to describe your problem a little better.You're right, I do it now. Let's say that I have to check if a size of a certain file doesn't change for about 3 sec. At the moment the only way I found is the following. There is a better way? Dim $size Dim $size_loop = 0 $file = file path While 1 Sleep(1000) $size2 = FileGetSize($file) If $size <> $size2 Then $size = $size2 Else $size_loop = $size_loop + 1 If $size_loop = 3 Then $size_loop = 0 Msg(1,"","OK", $file & " size haven't changed") EndIf EndIf WEnd Edited October 15, 2006 by masvil Link to comment Share on other sites More sharing options...
cppman Posted October 15, 2006 Share Posted October 15, 2006 (edited) This should work Also, there is no "sleep()" required. AdLibEnable("Timer", 1000) Global $OldSize = FileGetSize(@ScriptFUllPath) Global $nCount = 0 While 1 Sleep(10) WEnd Func Timer() $NowSize = FileGetSize(@ScriptFullPath) if ($NowSize <> $OldSize) Then MsgBox(0, "", "They are no longer the same!") $OldSize = $NowSize if ($nCount >= 3) Then AdLibDisable() Else $nCount += 1 EndIf EndFunc Edited October 15, 2006 by CHRIS95219 Miva OS Project 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