Script to check for any new file
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
Answers (2)
Please log in to answer
Posted by:
brenthunter2005
18 years ago
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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.