1.

Solve : program to monitor a file size then preform an action?

Answer»

Ok basically im looking for a program/source that can monitor a file, when the file expands then I need it to preform an action. Its only ONE file that I am monitoring. I really want source code since id rather add it to my own apps, crediting the author of course. Im not using it for anything phishy, im just about to leave so I dont have time to type what i need it for right now. I can do that later if someone needs me to. If anyone needs more info then please say so and i will reply back.Here is some VB6 code. Make a form with a timer. Give the timer an interval of how often you want to check for a change in the file.

Code: [Select]Option Explicit

Const THE_FILE As String = "B:\readme.txt"
Dim fSize As Long

Private SUB Form_Load()
fSize = FileLen(THE_FILE)
End Sub

Private Sub Timer1_Timer()
Dim newFSize As Long
newFSize = FileLen(THE_FILE)

If fSize <> newFSize Then
    MsgBox "It changed. Replace this with your code."
    fSize = newFSize
End If
End Sub
anyway that i can do that in c++? And thanks, if i can't do it in c++ then ill try to use that. CUS when i make the form I need it to run in the background withought it showing anything, and i dont know how to do that in vb6.don't have to specifically code in C++. here's  a vbscript
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFileToMonitor = "c:\test\file.txt"
Set objFile = objFS.GetFile(strFileToMonitor)
indicator = 0
While True
strFileSize = objFile.Size
WScript.Echo strFileSize
If strFileSize > indicator Then
indicator = strFileSize
WScript.Echo "filesize change: " & strFileSize
                ' Do your actions here...
End If
WScript.Sleep 10000

Wend


FindFirstChangeNotification() and FindNextChangeNotification() are easily accessible VIA C/C++.ok thank you guys, i just decided to GO with the vbscript, I think it will work best in that case.



Discussion

No Comment Found