LondonNDIB Posted March 11, 2007 Share Posted March 11, 2007 I'd like to continually monitor a certain folder and subfolder and take action when a file changes (file size, date modified, etc). I tried a simple continually-running loops that did some checks, but the problem was a 100% CPU load and high memory commitment. I was wondering if anyone had done something similar and might have some suggestions as to what direction I might want to try. Thanks. LD Link to comment Share on other sites More sharing options...
SadBunny Posted March 11, 2007 Share Posted March 11, 2007 I'd like to continually monitor a certain folder and subfolder and take action when a file changes (file size, date modified, etc). I tried a simple continually-running loops that did some checks, but the problem was a 100% CPU load and high memory commitment.I was wondering if anyone had done something similar and might have some suggestions as to what direction I might want to try. Thanks.LDI have a client-side script running on my clients that monitors (among other things) certain security-related file information, and when it detects changes, it reports to my server-side script. I see no other way to do this than polling for file changes, meaning to read the file information in question and comparing it to the previous information. To save CPU time but keep information actual, I have to balance a sleep() in my polling loop. I use Sleep(100), that way my files are checked 10 times a second which is WAY more than enough in my case, and the script CPU use is 0%. But I just tried it with Sleep(10) (this checks ofcourse 100x per second) and still the CPU use is 0%. When I don't Sleep() at all, CPU use goes up to 100% just like in your case ...Remember, your CPU is only human, flooding it with commands gets it drowned Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 11, 2007 Moderators Share Posted March 11, 2007 You can still use your current types, ie... filegetsize/date modification differ etc... but use AdlibEnable() instead. Global $aFiles[1] = ['PathToMyFile'], $aCurrentSize[1] = ['13390'] HotKeySet('{ESC}', '_EXITNOW') AdlibEnable('_FileChecks', 1000);Check files every 1 second While 1 Sleep(1000000) WEnd Func _FileChecks() For $iCC = 0 To UBound($aFiles) - 1 If FileGetSize($aFiles[$iCC]) <> Number($aCurrentSize[$iCC]) Then MsgBox(64, 'Differ', 'Values Differ for: ' & $aFiles[$iCC]);Do whatever if the file differs $aCurrentSize[$iCC] = FileGetSize($aFiles[$iCC]);reset new size EndIf Next EndFunc Func _EXITNOW() Exit EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Andrew Peacock Posted March 12, 2007 Share Posted March 12, 2007 Use a third-party DLL that does this and updates a log file, and then monitor the log file. eg, see Log Monitor mentioned in http://www.donationcoder.com/Forums/bb/ind...g44937#msg44937Andy Link to comment Share on other sites More sharing options...
ptrex Posted March 12, 2007 Share Posted March 12, 2007 @all, Why are you guys always looking to do it the difficult way ? These are all native windows functions as far as I know. WMI is the key to "almost" anything, also here. You need to use the : __InstanceCreationEvent __InstanceDeletionEvent __InstanceModificationEvent If I have a change I will post something the Example sript section. regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
ptrex Posted March 12, 2007 Share Posted March 12, 2007 @All Example added in the example scritps section of the forum. regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Andrew Peacock Posted March 12, 2007 Share Posted March 12, 2007 Ptrex, Many thanks. WMI is an unknown beast to me, and the 4d party software I mentioned offers good, reliable functionality without me learning anything new :-) Andy Link to comment Share on other sites More sharing options...
LondonNDIB Posted March 12, 2007 Author Share Posted March 12, 2007 Thanks a lot for all the hints, tips, and examples! I haven't had a chance to look at anything (moving to a new house right now) but I will! Thanks!!! - LD Link to comment Share on other sites More sharing options...
seandisanti Posted March 12, 2007 Share Posted March 12, 2007 Ptrex, Many thanks. WMI is an unknown beast to me, and the 4d party software I mentioned offers good, reliable functionality without me learning anything new :-)Andy<shrug> personally i'd rather learn something, and have 100% control over all aspects of the solution to my problem; if it were my problem that is. Link to comment Share on other sites More sharing options...
ptrex Posted March 12, 2007 Share Posted March 12, 2007 @allfor those who do want to learn something here it is :WMI Event Notification Exampleregards,ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
LondonNDIB Posted March 14, 2007 Author Share Posted March 14, 2007 Hi ptrex... thanks for the example! It works great for file creations and deletions... but I tried using it to detect file modifications, and no luck I don't care if a file gets deleted... but I need to know if a new file is created, and if an existing file changes (file size, timestamp at least). Thanks! -LD 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