Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Monitor files and subfolders of a folder (include all subfolders' files and folders)

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,30836
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Monitor files and subfolders of a folder (include all subfolders' files and folders)
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Monitor files and subfolders of a folder (include all s... - 2/8/2006 9:05:48 PM   
  archie

 

Posts: 1
Score: 0
Joined: 2/8/2006
Status: offline
I got a problem about monitoring a folder. I would like to monitor files and subfolders of a folder (include all subfolders' files and subfolders). I have no idea how many subfolders/files and how many subfolder-level users will create, modify, or delete. Therefore, I need a script to monitor everything what users did.

2 problems:
[1] how to monitor files and subfolders at the same time (or at the same script)?
[2] how to monitor a unknown subfolder, a unknown subfolder's subfolder, a unknown subfolder's subfolder's subfolder...... etc.

my original scripts are:
[1] monitor_files.vbs

 strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE " &_
  "Targetinstance ISA 'CIM_DirectoryContainsFile' and " &_
  "TargetInstance.GroupComponent= 'Win32_Directory.Name=""d:\\\\test""'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo objLatestEvent.TargetInstance.PartComponent
Loop



[2] monitor_folders.vbs (It's not work at all subfolder levels, but level 1.)

 strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE " &_
  "Targetinstance ISA 'Win32_SubDirectory' and " &_
  "TargetInstance.GroupComponent= 'Win32_Directory.Name=""d:\\\\test""'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo objLatestEvent.TargetInstance.PartComponent
Loop


many thanks, archie~
 
 
Post #: 1
 
 RE: Monitor files and subfolders of a folder (include a... - 2/9/2006 2:20:58 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
I would start by looking at this thread:
http://www.visualbasicscript.com/m_30784/tm.htm

The solution I present there should get you started. In your case, whenever you add a folder to monitor, you will want it to recurse the subfolders in it adding each of those to the monitoring as well.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to archie)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Monitor files and subfolders of a folder (include all subfolders' files and folders) Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts