0
votes

I need to be able to run a command with a corospoinding file. An example...

Eveytime cat.txt shows up in folder, run notpad.exe everytime cat2.txt shows up in folder, run calc.exe

Currently the vbs below works well, but only for one file found.

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

I tried to double it like this:

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
FileName = "c:\vbscript\cat2.txt"
Set FSO = CreateObject("Scripting.FileSystemObject")
Do
   If FSO.FileExists(FileName) Then 
       FSO.DeleteFile FileName
       CreateObject("WScript.Shell").Run "c:\windows\calc.exe"
   End If
   WScript.Sleep 1000
Loop

However I get an expected loop error, what am I doing wrong?

2

2 Answers

2
votes

Make it like this

Set FSO = CreateObject("Scripting.FileSystemObject")
Do
   If FSO.FileExists("c:\vbscript\cat.txt") Then 
       FSO.DeleteFile("c:\vbscript\cat.txt")
       CreateObject("WScript.Shell").Run "c:\windows\notepad.exe"
   End If

   If FSO.FileExists("c:\vbscript\cat2.txt") Then 
       FSO.DeleteFile("c:\vbscript\cat2.txt")
       CreateObject("WScript.Shell").Run "c:\windows\calc.exe"
   End If
   WScript.Sleep 1000
Loop
0
votes

You forgot to close the first Do - Loop