Question

I need a vbscript that monitors a folder for a specific file, when file is found it needs to execute a command then delete that file but continue to monitor the folder again for the same file incase it needs to run again.

This...

Set FSO = CreateObject("Scripting.FileSystemObject")
Do While 1>0
   If FSO.FileExists (file.txt) Then 
       FSO.DeleteFile (file.txt)
       CreateObject("WScript.Shell").Run "c:\windows\notepad.exe"
   End If
   WScript.Sleep 1000
Loop

Gave me an "object required: file" error.

update, this worked...

FileName = "c:\vbscript\cat.txt"
Set FSO = CreateObject("Scripting.FileSystemObject")
Do
   If FSO.FileExists(FileName) Then 
       FSO.DeleteFile FileName
       CreateObject("WScript.Shell").Run "c:\windows\notepad.exe"
   End If
   WScript.Sleep 1000
Loop
Was it helpful?

Solution

Simply create a script that infinitely loops, testing for file existence and if it does delete it.

FileName = "Path\To\FileName"
Set FSO = CreateObject("Scripting.FileSystemObject")
Do
   If FSO.FileExists(FileName) Then 
       FSO.DeleteFile FileName
   End If
   WScript.Sleep 1000
Loop
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top