Perform an action on several files at once (VBScript)

This code can be found in Chapter 8 of Windows XP Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' From the book "Windows XP Cookbook"
' ISBN: 0596007256

' This code shows how to iterate over all the zip files on a system
' ------ SCRIPT CONFIGURATION ------
strComputer = "."
strExtension = "zip"
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colFiles = objWMI.ExecQuery("select * from Cim_DataFile " & _
 " where extension = '" & strExtension & "'")
WScript.Echo "Files with a ." & strExtension & " extension:"
intCount = 0
for each objFile in colFiles
 WScript.Echo " " & objFile.Name
 
 ' Do some action here

 intCount = intCount + 1
next
WScript.Echo "Total: " & intCount

This code has been viewed 1098 times.

New from the creators of TechTasks.com: StatSheet.com