Option Explicit WScript.Echo Join( GetFilesLE( WScript.Arguments.Unnamed.Item(0) ), vbCrLf ) Function GetFilesLE( strFilespec ) ' Name : GetFilesLE ' Function : List all files matching the specified filespec, all DOS wildcards allowed; ' Light Edition of GetFiles( ) function, but FILE names only, no directories ' Returns : An array of all matching file names (no path), or a single element array with the text "Error" ' Remarks : Since no folder can be specified, the current directory will be assumed. ' DOS wildcards "*" and "?" are allowed in the file name as well as in the extension. ' Author : Rob van der Woude, http://www.robvanderwoude.com ' Version : 1.00, 2017-02-02 Dim colFiles, objFile, objFSO, objRE, wshShell Dim strFiles, strPattern ' Return "Error" on missing or invalid filespec GetFilesLE = Array( "Error" ) If Trim( strFilespec ) = "" Then Exit Function If InStr( strFilespec, "\" ) Then Exit Function Set wshShell = CreateObject( "WScript.Shell" ) Set objFSO = CreateObject( "Scripting.FileSystemObject" ) Set objRE = New RegExp ' Convert DOS wildcards to regex pattern objRE.Pattern = "([\.\(\)\[\]\{\}\$])" objRE.Global = True objRE.IgnoreCase = True strPattern = objRE.Replace( strFilespec, "\$1" ) strPattern = Replace( strPattern, "?", "[^\\]" ) strPattern = Replace( strPattern, "*", "[^\\]*" ) objRE.Pattern = "(^|\\)" & strPattern & "$" ' Get a collection of files Set colFiles = objFSO.GetFolder( wshShell.CurrentDirectory ).Files strFiles = "" ' Iterate through the list of files For Each objFile In colFiles ' Check if the file name matches filespec If objRE.Test( objFile.Path ) Then ' Add the file to the list strFiles = strFiles & ";" & objFile.Name End If Next ' Return the list of files as an array GetFilesLE = Split( Mid( strFiles, 2 ), ";" ) ' Cleanup Set colFiles = Nothing Set objRE = Nothing Set objFSO = Nothing Set wshShell = Nothing End Function