Followers 0

# if size of a file not changes...

## 5 posts in this topic

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?

##### Share on other sites

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[ #### Share this post ##### Link to post ##### Share on other sites 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 #### Share this post ##### Link to post ##### Share on other sites #4 · Posted (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 by masvil #### Share this post ##### Link to post ##### Share on other sites #5 · Posted (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 by CHRIS95219