We help IT Professionals succeed at work.

How to execute a script in a bunch of files that ends with a keyword using VBS?

acunaara
acunaara asked
on
I want to execute a script on several files that are inside a folder but only for those files which ends with the keyword "qa"

for example:
I have a folder with a lot of below files
settingsqa.txt
settingsqb.txt
settings2qa.txt
settings2qb
configqa.txt
configqb.txt


and i want only execute the script for the ones:
settingsqa.txt
settings2qa.txt
configqa.txt
Comment
Watch Question

Top Expert 2007
Commented:
Something like this...

dim objfso: set objfso = createobject("scripting.filesystemobject")
dim objFolder : set objfolder = objfso.getfolder("c:\temp")
for each oFile in objFolder.Files
  if lcase(objfso.getextensionname(ofile)) = "txt" then
    strFilename = objFSO.getbasename(ofile)
    if lcase(right(strFilename,2)) = "qa" then
      'do something
    end if
  end if
next

Open in new window

Author

Commented:
Excellent!! Thanks