Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using windows explorer & file dialog box from vbs 3

Status
Not open for further replies.

barny2006

MIS
Mar 30, 2006
521
US
hi,
is there a way to deploy a file dialog box from within a vbs/hta, select files and folders, and then pass them to the program?

the code that i have been working on, seems to be a single level folder listing of files and subfolders. it would be a lot better if it can use a file dialog box.

any ideas would be greatly appreciated.

 
should find plenty of examples if you do a search on this forum
'one way

Function ChooseFile
Set f = CreateObject("SAFRCFileDlg.FileOpen")
f.OpenFileOpenDlg
ChooseFile f.FileName
Set f = Nothing
End Function


Set ObjFSO = CreateObject("UserAccounts.CommonDialog")

ObjFSO.Filter = "VBScripts|*.vbs|Text Documents|*.txt|All Files|*.*"

ObjFSO.FilterIndex = 3

ObjFSO.InitialDir = "c:\myscripts"

InitFSO = ObjFSO.ShowOpen

If InitFSO = False Then
Wscript.Echo "Script Error: Please select a file!"
Wscript.Quit
Else
Wscript.Echo "You selected the file: " & ObjFSO.FileName
End If

 
thanks mrmovie,
it worked great.
it popped the file dialog box. however, here's my dilema:
i'm trying to display a windows explorer type listing that you can select file(s) and folders(s) to be copied to another location. maybe i didn't state the problem correctly. file dialog box will give you a single file to Open. but, it won't let you select multiple files/folders. however, windows explorer will. is there another object that can do this? i hate to re-invent the wheel and write a lengthy explorer type listing with multi select box.
thanks.
 
the solution that i'm looking for is similar to file dialog box with ability to select multiple files/folders. i'm guessing explorer could do it. any ideas?
 
does this help?
Function PickFolder(strStartDir As Variant) As String
Dim SA As Object, f As Object
Set SA = CreateObject("Shell.Application")
Set f = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
If (Not f Is Nothing) Then
PickFolder = f.Items.Item.Path
End If
Set f = Nothing
Set SA = Nothing
End Function
 
Try this:

Code:
Const cdlOFNAllowMultiselect = 512

Set ObjFSO = CreateObject("UserAccounts.CommonDialog")
ObjFSO.Filter = "VBScripts|*.vbs|Text Documents|*.txt|All Files|*.*"
ObjFSO.FilterIndex = 3
ObjFSO.InitialDir = "c:\myscripts"
ObjFSO.Flags = cdlOFNAllowMultiselect
InitFSO = ObjFSO.ShowOpen

If InitFSO = False Then
	Wscript.Echo "Script Error: Please select a file!"
	Wscript.Quit
Else
	Wscript.Echo "You selected the file: " & ObjFSO.FileName
End If

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
cool.
thanks mrmovie. this would work. it's still a single item selection. but, i can expand the folder files in a multi list box and select the files from that.
thanks again.
 
mrmovie, your last post looks very familiar to me ;-)
 
thanks, dm.
this one did it.
thanks so much! it's working great!
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top