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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browse to folder in .hta ? 3

Status
Not open for further replies.

strebor

Technical User
Nov 24, 2004
66
US
I need a way for users of an html application (.hta) to browse to a folder. The application's result is a file. I would like the users to be able to choose the folder where the file is saved.

I can use a simple <input type="file"... to allow the users to select a file; but, how do I provide them with a way to simply choose a folder using a similar browse dialog?
 
You may try this function:
Function PickFolder(strStartDir)
Dim SA, F
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

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you very mcu, PH! It works perfectly. Here is it in a sample .hta application:

<html>
<head>
<HTA: Application
Border = Thick
BorderStyle = Complex
ShowInTaskBar = No
MaximizeButton = No
MinimizeButton = No
>

</object>
<script language = "VBScript">

Sub ChooseSaveFolder
strStartDir = "c:\"
userselections.txtFile.value = PickFolder(strStartDir)
End Sub

Function PickFolder(strStartDir)
Dim SA, F
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

</script>

</head>
<body>
<form name="userselections">
<input type = "text" name = "txtFile" size="50" />

<input type = "button" value = "Browse ..." onClick="ChooseSaveFolder" />
</form>
</body>
</html>

-Norm
 
How do you then use the path selected in your code?
Say they pick c:\test

I want to use that information as user input in the script.

like for a text box I would use:
Code:
Dim FdrName
FdrName = txtFolderName.Value

Thanks for any tip,
Cheers!
Scully
 
Nevermind I got it:

Code:
Sub CheckMaster
    Master = userselections.txtFile.value
    	If userselections.txtFile.value ="" Then
    		msgbox "Please Enter Database Name"
    	Else
    		msgBox "Verifing " & Master
        End If		
End Sub

Gracias for the post guys
Scully
 
I have one more question.

Is there a way to just have the folder name saved in "userselections.txtFile.value" rather than the whole path?

For example you browse to C:\test\blah\something
And want to use the folder "something" as a variable in the script.

Let me know if you have any ideas.
Thanks,
S
 
Mid(userselections.txtFile.value, 1+InStrRev(userselections.txtFile.value,"\"))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That worked great!
Not sure if this is the best way to accomplish what i'm doing but here is the code.

Code:
html>
<head>
<HTA: Application
    Border = Thick
    BorderStyle = Complex
    ShowInTaskBar = No
    MaximizeButton = No
    MinimizeButton = No
    >

</object>
<script language = "VBScript">

Dim Master
Dim Master1

Sub ChooseSaveFolder
    strStartDir = ""
    userselections.txtFile.value = PickFolder(strStartDir)
End Sub 

Function PickFolder(strStartDir)
Dim SA, F
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 


Sub CheckMaster
    Master = userselections.txtFile.value
    	If userselections.txtFile.value ="" Then
    		msgbox "Please Enter Database Name"
    	Else
			msgBox "Master is: " & Master
		TrimMaster
        End If		
End Sub

Sub TrimMaster
	Master1 = Mid(userselections.txtFile.value, 1+InStrRev(userselections.txtFile.value,"\"))
    msgBox "Master1 is: " & Master1
End Sub

</script>

</head>
<body>
<form name="userselections">
<input type = "text" name = "txtFile" size="50" />

<input type = "button" value = "Browse ..." onClick="ChooseSaveFolder" />
<input type="button" value="Submit" name="run_button"  onClick="CheckMaster">
</form>
</body>
</html>

Thanks again,
Scully
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top