(view source code of wildcardsle.vbs as plain text)
Option ExplicitWScript.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 filespecGetFilesLE = 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 patternobjRE.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 filesSet colFiles = objFSO.GetFolder( wshShell.CurrentDirectory ).Files
strFiles = ""
' Iterate through the list of filesFor Each objFile In colFiles
' Check if the file name matches filespecIf objRE.Test( objFile.Path ) Then
' Add the file to the liststrFiles = strFiles & ";" & objFile.Name
End If
Next ' Return the list of files as an arrayGetFilesLE = Split( Mid( strFiles, 2 ), ";" )
' CleanupSet colFiles = Nothing
Set objRE = Nothing
Set objFSO = Nothing
Set wshShell = Nothing
End Function
page last modified: 2025-10-11; loaded in 0.0080 seconds