/build/static/layout/Breadcrumb_cap_w.png

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)

Posted by: brenthunter2005 18 years ago
Fifth Degree Brown Belt
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
Posted by: Naffcat 18 years ago
Senior Purple Belt
0
This is excellent, many thanks
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ