'******************************************************** ' FolderSelectDialog.vbs ' Alan Kaplan alan at akaplan dot com 12-15-2005 ' after getting tired of reading it will not work... ' Based in part on FileSelectDialog.vbs by Gunter Born ' Kaplan added handling of special folders ' Tested okay with XP and 2000 ' Uses the shell browseforfolder method to select a folder '******************************************************** Option Explicit ' Flags for the options parameter Const BIF_returnonlyfsdirs = &H0001 'Don't want no steenkin' filenames Const BIF_ShowAllObjects = &H0008 'ReturnFSAncestors. This will give you typical root view 'XP has My Computer, My Network Places not seen on 2000 Const BIF_editbox = &H0010 'Show active selection, allows manual input Dim wshShell 'Wscript object Set wshShell = WScript.CreateObject("WScript.Shell") '=== Example === Dim SrcFolder, DestFolder SrcFolder = BrowseForFolder("Choose a root folder of VOB files, then click OK:", _ BIF_returnonlyfsdirs + BIF_editbox + BIF_ShowAllObjects,"") If Len(SrcFolder)=0 Then Wscript.Quit 1 DestFolder = BrowseForFolder("Choose a root folder for converted .MPG files, then click OK:", _ BIF_returnonlyfsdirs + BIF_editbox + BIF_ShowAllObjects,"") If Len(DestFolder)=0 Then Wscript.Quit 2 call GetDir(SrcFolder,DestFolder) '= End Example === Function BrowseForFolder(title, flag, dir) ' title = Text shown in the dialog box ' flag = values controlling BrowseForFolder behavior ' dir = Initial directory (can be ""). ' dir most useful when not using BIF_ShowAllObjects On Error Resume Next Dim oShell, oItem, strSelection ' Create Shell object. Set oShell = WScript.CreateObject("Shell.Application") ' Invoke Browse For Folder dialog box. Set oItem = oShell.BrowseForFolder(&H0, title, flag, dir) strSelection = oItem.Title If Err <> 0 Then 'cancelled Set oShell = Nothing Set oItem = Nothing Exit Function End If ' If colon found then get drive letter from the title. No array If InStr(strSelection, ":") Then BrowseForFolder = mid(strSelection,InStr(strSelection, ":")-1, 2) Else 'Handle all other special cases where path not returned Select Case strSelection Case "Desktop" BrowseForFolder = wshShell.SpecialFolders("Desktop") Case "My Documents" BrowseForFolder = wshShell.SpecialFolders("MyDocuments") Case "My Computer" MsgBox "Invalid selection",vbCritical + vbOKOnly,"Error" WScript.Quit Case "My Network Places" MsgBox "Invalid selection",vbCritical + vbOKOnly,"Error" WScript.Quit Case Else ' Finally try to retrieve the full path a la Born BrowseForFolder = oItem.ParentFolder.ParseName(oItem.Title).Path End Select End If 'Cleanup Set oShell = Nothing Set oItem = Nothing 'make sure they all end in \ If Right(browseForFolder,1)<> "\" Then browseforfolder = browseforfolder & "\" End If 'Alternate make sure they all end without \ ' If Right(browseForFolder,1) = "\" Then ' browseforfolder = left(BrowseForFolder,Len(BrowseForFolder)-1) ' End If On Error GoTo 0 End Function '====================== Sub GetDir(idir,odir) Dim oCurrDir, oFolder, oFolders, oFile, oFiles Dim oFileSys Set oFileSys = CreateObject("Scripting.FileSystemObject") Set oCurrDir = oFileSys.GetFolder(idir) Set oFolders = oCurrDir.SubFolders Set oFiles = oCurrDir.Files ' get all sub-folders in this folder For Each oFolder In oFolders 'go to each one Call GetDir (oFolder,odir) Next Set oFile = Nothing For Each oFile In oFiles If InStr(1, oFile.Name, ".VOB", 1) > 0 Then Call ConvertVOB (oFile.Path, odir) End If Next End Sub '================================ Sub ConvertVOB(fname,opath) Dim mpgname, VideoPID, AudioPID, VideoReDo, openFlag, outputFlag VideoPID = &he0 AudioPID = &h80 mpgname = Left(fname, InStrRev(fname, "\") - 1) mpgname = Mid(mpgname, InStrRev(mpgname, "\") + 1 ) mpgname = opath & mpgname & ".mpg" Set VideoReDo = WScript.CreateObject( "VideoReDo.Application" ) openFlag = VideoReDo.FileOpenBatchPIDS( fname, VideoPID, AudioPID ) if openFlag = false then Wscript.echo( "? Unable to open file/project: " + fname) Wscript.Quit 3 end if VideoReDo.AudioAlert = false ' Open the output file and start processing. outputFlag = VideoReDo.FileSaveAsEx( mpgname, 1 ) if outputFlag = false then Wscript.Echo("? Problem opening output file: " + mpgname) Wscript.Quit 4 end if ' Wait until output done. while( VideoRedo.IsOutputInProgress() ) Wscript.Sleep 2000 wend VideoReDo.Close() ' 'MsgBox fname, vbOKOnly, "File to convert: " & mpgname End Sub