VBS script for starting XXX.cmd if XXX.txt is in the directory

VBS script for starting XXX.cmd if XXX.txt is in the directory @ www.Vasilev.link DevOps consultant
Jan 20, 2015

When you have to automate some process and you need to start different commands depends on some logic.. you can use the script to start the script with some name if there is a text file with the same name in the source directory.
Here the trigger is the text file:

Option Explicit
DIM fso, net, shell, filesys, i, arrFiles
arrFiles = Array("name_of_file1", "name_of_file2",)
 
Set fso = CreateObject("Scripting.FileSystemObject")
set net = CreateObject("WScript.Network")
set shell = CreateObject("WScript.Shell")
set filesys = CreateObject ("Scripting.FileSystemObject")
 
For i = LBound(arrFiles) to UBound(arrFiles)
 If fso.FileExists(arrFiles(i)+".txt") Then shell.run(arrFiles(i)+".cmd")
filesys.GetFile(arrFiles(i)+".txt").Delete End if
Next