LISTING 1: Edir.vbs 'edir.vbs 'Enhanced directory utility. Option Explicit Const ReadOnly = 1 Const Hidden = 2 Const System = 4 Const Archive = 32 Const Compressed = 2048 Dim strCriteria, objFile, objFSO, nCount, strOut If StrComp(Right(Wscript.Fullname,11), _ "cscript.exe", vbTextCompare) <> 0 Then Wscript.Echo "You must use Cscript to run this script" Wscript.Quit End If If Wscript.Arguments.Count < 2 _ Or Wscript.Arguments.Count > 3 Then ShowUsage Wscript.Quit -1 End If 'If three arguments passed, third argument controls output. If Wscript.Arguments.Count = 3 Then strOut = ReplaceCriteria(Wscript.Arguments(2)) End If Set objFSO = CreateObject("Scripting.FileSystemObject") 'Check whether search folder exists. If Not objFSO.FolderExists(Wscript.Arguments(0)) Then Wscript.Echo "Path '" & Wscript.Arguments(0) & "' not found " Wscript.Quit -1 End If strCriteria = ReplaceCriteria(Wscript.Arguments(1)) nCount = 0 'Recurse the specified folder. RecurseDirs objFSO.GetFolder(Wscript.Arguments(0)) 'Check whether no files were found. If nCount = 0 Then WScript.Echo "No files found that meet search criteria" End If Sub ShowUsage WScript.Echo "edir.vbs Enhanced directory utility." & vbCrLf & _ "Syntax:" & vbCrLf & _ "edir.vbs path criteria [filter]" & vbCrLf & _ "path path to folder to search " & vbCrLf & _ "criteria criteria to filter files on " End Sub BEGIN CALLOUT A Function GetExt(strPath) GetExt = objFSO.GetExtensionName(strPath) End Function END CALLOUT A 'Recurse through specified folder. Sub RecurseDirs(objFolder) Dim objSub 'Enumerate each file in folder and execute expression 'against filename. For Each objFile In objFolder.Files 'Check file criteria. If Eval(strCriteria) Then 'Increase file count. nCount = nCount + 1 If strOut = "" Then Wscript.StdOut.WriteLine objFile.Path Else Wscript.StdOut.WriteLine Eval(strOut) End If End If Next 'Recurse each folder in current folder. For Each objSub In objFolder.SubFolders RecurseDirs objSub Next End Sub BEGIN CALLOUT B 'Replaces all properties surrounded by square brackets with 'objFile.; replaces the "`" character (ASCII 39) with double quotes. Function ReplaceCriteria(strCriteria) Dim objRegExp 'Create a regular expression object and replace. Set objRegExp = New RegExp objRegExp.Global = True objRegExp.Pattern = "\[\w+\]" 'Replace all occurences of the ` character with quotes. strCriteria = Replace(strCriteria, "`", """") 'Replace [ext] (extension criteria) with GetExt function. strCriteria = Replace(strCriteria, "[ext]", _ "GetExt(objFile.Path)",1, -1, vbTextCompare) 'Replace all properties surround with square brackets. strCriteria = objRegExp.Replace(strCriteria, GetRef("Repl") ) ReplaceCriteria = strCriteria End Function END CALLOUT B 'Used by regular expression Replace function. Function Repl(strMatch, nPos, strSource) Repl = "objFile." & Mid(strMatch,2,Len(strMatch) - 2) End Function