Sunday, December 19, 2021

vbscript: get list of files with a particular extension displayed as an array in message box

 Reference links used:


https://stackoverflow.com/questions/18920310/vbscript-to-search-for-all-files-with-an-extension-and-save-them-to-a-csv

https://www.tutorialspoint.com/vbscript/vbscript_arrays.htm


Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = objFSO.GetFile(Wscript.ScriptFullName).ParentFolder.Path

Set objFolder = objFSO.GetFolder(objStartFolder)
Dim a(),count
ReDim a(-1) 
count = 0
Set colFiles = objFolder.Files
For Each objFile in colFiles
    
    If LCase(objFSO.GetExtensionName(objFile.Name)) = "wmv" Then
    count = count + 1
    redim Preserve a(count-1)
    a(count-1) =  objFile.Name
    'Wscript.Echo objFile.Name
    End If
Next

arrayString =  Join(a, vbNewLine)
MsgBox(arrayString)

No comments:

Post a Comment