Can anyone tell me how I can script a check for any new file that appears in a folder? I've used fileexist and folder exist before but just want to write a script to check periodically if a new file appears in a folder and perform an action on it.
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
SourceFolder = "c:\temp"
SourceFolder = Replace(SourceFolder, "\", "\\\\")

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE Targetinstance ISA 'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent='Win32_Directory.Name=""" & SourceFolder & """'")
wscript.echo "Now watching for events"

Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo objLatestEvent.TargetInstance.PartComponent

Loop
Answered 08/07/2006 by: brenthunter2005
Fifth Degree Brown Belt

Please log in to comment
0
This is excellent, many thanks
Answered 08/09/2006 by: Naffcat
Senior Purple Belt

Please log in to comment
Answer this question or Comment on this question for clarity