Search code examples
javascripthtmlvbscripthta

HTML application drop down - from an array of folders


I've got an HTML application, where I want users to select a folder from a drop-down list.

To populate this drop-down list, I would need the application to check for all folders in a directory and list those folders in the drop-down list.

Is this possible with JavaScript or VB Script?


Solution

  • OK, found the answer myself anyway. Here's an example for anybody else wanting to do this:

    HTML:

    <div class="divcontainersub">
        <label for="folder">Select Folder:&nbsp;&nbsp;&nbsp;&nbsp;</label>
            <select id="folder" class="inputfields" tabindex="1" name="folder" size="1" style="width:278px;"">
                <option value="0">Select a folder...</option>
            </select>
    </div>
    

    VB (within the Window_OnLoad Sub):

    Dim oFSO, oFolder, oSubFolder, i, oNewOption
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFolder = oFSO.GetFolder("\\Server\Share")
    Set oSubFolder = oFolder.SubFolders
    
    For Each i in oSubFolder
        Set oNewOption = window.document.CreateElement("OPTION")
        oNewOption.Text = i.Name
        oNewOption.Value = i.Name
        Folder.Add(oNewOption)
    Next