指定したフォルダから再帰的に処理を実行してみる
Option Explicit Dim objApl Dim objFileSys Dim objFolder Dim objFolderItems '====== シェルアプリケーションオブジェクト作成 =======. Set objApl = WScript.CreateObject("Shell.Application") Set objFileSys = CreateObject("Scripting.FileSystemObject") '====== フォルダのオブジェクトを作成 =======. Set objFolder = objApl.NameSpace( InputBox("検索対象のトップフォルダのパスを入力", "") ) '====== 検索処理の呼び出し =======. Call SearchFiles ( objFolder.Item() ) '====== 開放 =======. Set objFolderItems = Nothing Set objFolder = Nothing Set objFileSys = Nothing Set objApl = Nothing Sub SearchFiles( paramFolderItems ) Dim objFolderItemsSub Dim objItem Dim i For i = 0 To paramFolderItems.Count-1 Set objItem = paramFolderItems.Item( i ) If objItem.IsFolder Then ' 再帰検索。1つ下のサブフォルダへ. Set objFolderItemsSub = objItem.GetFolder Call SearchFiles (objFolderItemsSub.Items()) Else If LCase(objFileSys.GetExtensionName(objItem.Name)) = "xls" _ Or LCase(objFileSys.GetExtensionName(objItem.Name)) = "xlsx" Then WScript.Echo "Excel : " & objItem.Name ElseIf LCase(objFileSys.GetExtensionName(objItem.Name)) = "txt" Then WScript.Echo "Text : " & objItem.Name End If End If Next Set objItem = Nothing Set objFolderItemsSub = Nothing End Sub