Solved VBScript to find file and return filtered folder path

Microsoft Internet explorer 6 resource k...
June 18, 2012 at 18:28:30
Specs: Windows 2008
I need a .vbs to search subfolders of %programfiles%\adobe and find acrobat.exe (eg. %programfiles%\Adobe\Acrobat 9.0\Acrobat) then return and filter the results to the Acrobat version folder (eg. Acrobat 9.0).

I have an old batch which does this but I'm not sure on the VB side :
@ECHO OFF

PUSHD "%programfiles%\java"
FOR /f "tokens=1-4 delims=\" %%a IN ('DIR /b /s "javaw.exe"') DO ECHO %%a\%%b\%%c\%%d
POPD
PAUSE

This is what I have so far to search %programfiles%\Java and return all files in subdirectories:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "%programfiles%\Java"

Set objFolder = objFSO.GetFolder(objStartFolder)
Wscript.Echo objFolder.Path
Set colFiles = objFolder.Files
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
Wscript.Echo

ShowSubfolders objFSO.GetFolder(objStartFolder)

Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
Wscript.Echo
ShowSubFolders Subfolder
Next
End Sub


See More: VBScript to find file and return filtered folder path

Report •


#1
June 19, 2012 at 06:19:40
What, exactly, are you trying to accomplish? If you're just trying to poll the version of Acrobat, WMI would help there.

How To Ask Questions The Smart Way


Report •

#2
June 19, 2012 at 16:24:25
Thanks for your reply. I'm needing this vbs for MSI packages which install its files within its prereq softwares folder. eg. 3rd party Acrobat plugin software. So I need to check if the prereq software .exe exists and if it does, what its folder name is, in this case Acrobat 9.0. This is to avoid static folder information as the prereq folder could be different names depending on the version. If you need more info just let me know.

Report •

#3
June 23, 2012 at 20:08:52
✔ Best Answer
Fair enough. There should be a better way, presumably by querying the registry, but I don't have Acrobat installed, so I can't go hunting by myself.

Const startDir = "Adobe"
Const fileName = "acrobat.exe"
'ssfPROGRAMFILES = 0x26
programFiles = CreateObject("Shell.Application").Namespace(&H26).Self.Path
Set fso = CreateObject("Scripting.FileSystemObject")
dir = programFiles & "\" & startDir

If fso.FolderExists(dir) Then _
  file = FindFile(LCase(fileName), fso.GetFolder(dir))
If Len(file) = 0 Then
  WScript.Echo "Error: File Not Found"
  WScript.Quit 2
End If
Set folder = fso.GetFolder(file & "\..\..")
WScript.Echo folder.Name & ": " & folder


WScript.Quit
Function FindFile(ByRef sName, ByRef oFolder) 'As String
  FindFile = ""
  For Each file In oFolder.Files
    If LCase(file.Name) = sName Then
      FindFile = file
      Exit Function
    End If
  Next 'file
  For Each dir In oFolder.SubFolders
    FindFile = FindFile(sName, dir)
    If Len(FindFile) Then _
      Exit Function
  Next 'dir
End Function

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
June 26, 2012 at 05:22:41
Thanks, you're a champ! That was exactly what I was looking for.

Report •


Ask Question