[web] How to select a Folder or Device in HTML

Started by
5 comments, last by igni ferroque 18 years, 10 months ago
OK, here is the question, I have a page and I need to show the visitor a window where he can select a device or a folder located in his computer and retrieve the selected path, I tried with <input type="file"> but it only allows me to select files, I need to select folders or drives (C:\,A:\,D:\, etc;) Hope someone can help me
My site Jvitel.com
Advertisement
There is no way to upload directories via HTTP PUT.
Free Mac Mini (I know, I'm a tool)
You can do this in VBScript or &#106avascript. Check out this page:

http://authors.aspalliance.com/brettb/VBScriptDrivesCollection.asp

There are a few other ways of accomplishing this as well. I believe you can use the ComDlg32.ocx, but it'll only work if the user of your page already has it. I believe that the Scripting object is standard on Windows systems...however, this likely won't work on Unix. Actually, the fact that you're selecting drives already implied that it won't be usable on *nix.

Edit:

However, there's not a simple way to upload the entire directory using this process. You could, perhaps, use scripting to dynamically create a hidden input field for each file in the path/drive selected, something like the following:

Drive "C:\Temp" contains 3 files:
1. characters.txt
2. story.txt
3. config.ini

Then on the scripting event when the user clicks "Submit", first dynamically create 3 hidden input elements with number-incremented names like "file1", "file2", "file3"... then have the code submit the form. You'd then need some server-side coding to search for parameters until one is not found (e.g. the code would find a value for form elements "file1", "file2", "file3", but not "file4", so it would stop searching). I hope this helps some...note the limitations of browsers and OS's though.
Thanks for the replies, I didn't mention the fact that I don't want to upload the entire directory, just want the user to select a path, wich I'll use to scan for viruses, so all I need is a directory dialog and a path, a string like "C:\My documents" as return.

Thanks.
My site Jvitel.com
?

... you're making a virus-scanning web page?
No, it's just an interface for a security suite wich contains an antivirus, the configuration interface is made on webpages (using something like jsp) so, the antivirus executes locally, I just need to get the user's input, in this case the folder's path to be scanned and store it into a config file wich the antivirus will read.

I was thinking maybe a java applet could display a Directory Dialog, but I don't know if that's posible or how to do it.
My site Jvitel.com
Quote:Original post by J_Vitel
No, it's just an interface for a security suite wich contains an antivirus, the configuration interface is made on webpages (using something like jsp) so, the antivirus executes locally, I just need to get the user's input, in this case the folder's path to be scanned and store it into a config file wich the antivirus will read.

I was thinking maybe a java applet could display a Directory Dialog, but I don't know if that's posible or how to do it.


I'm still confused. That would take a whopping five minutes to accomplish in .NET. To do it via a web page (HTA, I'm assuming?), you would have to use VBScript or JScript as Mattman described.
Free Mac Mini (I know, I'm a tool)

This topic is closed to new replies.

Advertisement