File watcher Script

Tags:
VBScript
I want to write a scrip to watch whether the file has come to specified path
ASKED: October 30, 2007  11:39 AM
UPDATED: May 29, 2008  10:43 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Something like this.

<pre>Dim filesys,demofile, createdate
Set filesys = CreateObject(“Scripting.FileSystemObject”)
ON ERROR RESUME NEXT
Setdemofile = filesys.GetFile(“filename”)
IF err.number <> 0 then ‘File didn’t exist
else ‘file did exist
end if</pre>

Alessandro Panzetta
Another approach could be a kind of active monitoring on a given folder, that’s to say:

<pre>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=”"c:\\\\scripts”"‘”)
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo objLatestEvent.TargetInstance.PartComponent
Loop</pre>

The script above will monitor file creation in the <i>c:\scripts</i> folder and echo a message everytime a file is created.
Bye

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following