Teemo
Teemo

Reputation: 23

Create Sub-folder list when dropdown option is selected

I have a HTA code below which list all sub-folder in a specific folder. My question is that if I click one sub-folder from list, how can it auto-create the second list that gives me all child-folder in that sub-folder? and so on till there is no more child-folder found, the last child-folder needs to list all files in it. Also how can I add a extra option in the end of each list called [new folder] that will pop-up a window allowing enter the name to create a new folder.

In the end if click [submit] button, It will open the last child-folder I choose in windows explorer. I am new to vbs, so please help


<HEAD>
  <TITLE>K Drive Program Structure</TITLE>
  <HTA:APPLICATION ID="Hello" 
    APPLICATIONNAME="K Drive Program Structure" 
    BORDER="Dialog"
    CAPTION="Yes"
    SCROLL="NO"
    SHOWINTASKBAR="yes"
    SINGLEINSTANCE="yes"
    SYSMENU="Yes"
    WINDOWSTATE="maximize">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="VBScript">

Sub UpdateList
  For Each opt In list.Options
    opt.RemoveNode
  Next

  Set fso = CreateObject("Scripting.FileSystemObject")
  For Each f In fso.GetFolder("K:\AppData").SubFolders
    Set opt = document.createElement("OPTION")
    opt.Text  = f.Name
    opt.Value = f.Path
    list.Add(opt)
  Next
End Sub
</SCRIPT>

<H2>K Drive Structure</H2>
<P>CUSTOMER
<select id="list" name="list" onMouseOver="UpdateList"></select><P>

<BR>
<BR>
<Input Type = "Button" Name = "btn01" VALUE = "SUBMIT">
<Input Type = "Button" Name = "btn02" VALUE = "CLOSE">
<BR>
<BR>

</BODY>

Thanks for help

Upvotes: 0

Views: 1053

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200323

Why aren't you using the Shell.BrowseForFolder method like I suggested? Trying to re-invent it in HTA will always be awkward.

As for your question, you need to add an onChange handler to the <select> tag:

<select id="list" name="list" onMouseOver="UpdateList" onChange="EnumSubFolders">
</select>

and a procedure EnumSubFolders to enumerate the child folders:

Sub EnumSubFolders
  Set fso = CreateObject("Scripting.FileSystemObject")
  For Each opt In list.options
    If opt.selected Then
      Set sf = fso.GetFolder(opt.value).SubFolders
      'do stuff with sf
      Exit For
    End If
  Next
End Sub

You may need to apply some modifications to UpdateList, too (like remembering the currently selected option before refreshing the list).

Upvotes: 1

Related Questions