All Forums >> [Scripting] >> Post a VBScript >> [Updated] File browser/ "Open" dialog in HTA Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
I needed a file browser because on w98 I can't use the User object that allows using the windows "open" dialog. Yet I can use the IE open dialog but it doesn't allow filtering by extention. So I had to sort of reinvent the wheel.
Now the real advantage of this HTA over the default dialog is that you can select files from different directories before submiting your selection.
You don't need to hold the Ctrl key to make multiple selections, but you can't use Shift+Sparrow to select groups of files.
And HTA allows you to creates your own features:
-Select all, Unselect all, Reset and other buttons -Shows the list of the files selected -Shows the number of files in the directory after filtering -Separate folders from files -Path, extention filter, detail view and sorting argument customizable from launch script
Not featuring yet: -Address bar -Buttons for changing extention filter, detail view and sorting argument from the HTA file browser -List of subfolders not sorted
Use:
Take the example from the script below.
commandline is: WshShell.Run "filebrowser3.hta /[path] /[extentions separated by commas] /O:[sort by argument] /V:[view arguments]", 3, true
Sort argument and view argument are moreless the same as in DOS:
Sort by (/O:) : N - by name E - by extension A - by last access date S - by size D - by date and time
View details (/V:) : A - last access date S - size D - date and time B - attribute L - full details
Arguments can be written in whatever order you wish, with or without white space or be obmited without generating error.
When the dialog open click on file names to select them. After the dialog is closed, the script will have to read the list from "list.tmp".
Here is the HTA code Save it as "filebrowser.hta"
< Message edited by Fredledingue -- 11/21/2006 8:02:30 AM >
The ability to select multiple files from multiple paths is very cool. It doesn't work for my C: drive (C:\SubFolder works fine), but the D: drive works fine. If I start it on the C: drive or go up a level to the C: drive I get an error Line 1 Char 1 Invalid procedure call or argument.
I also have a problem where the code bleeds into the HTML:
Indeed, it doesn't work on C: drive when you launch it directly on C: as parameter, but I can lauch it from My Document and go up to C:, then it works normaly. I can't launch it on D: neither. I guess that for drives we need some other code as they are not folders,while in some case can be manipulate like a folder.
I don't know what to say about the "source bleeding" in the page. I'll need more precision about that. What files are you attempting to list? What's your OS? IE version? etc
With the bleeding it doesn't matter what files I'm trying to view. It never occurs when I launch the browser, but I'm able to recreate the bleed by doing the following. Select at least one file, then change the folder twice by clicking on a folder or selecting "Up one level". After thatn I get "MyString = ...." before the list of folders. If I don't select a file I can browse through the folders as much as I want and it works fine.
An interesting quirk with this is if I select another file and then move to another folder. The last file i selected will be in bold in front of the folders list. If I browse to another folder (without selecting another file) after that, I get the "MyString=..." again. If I hit reset and go to another folder, then the file name will be the last file in the file list.
The bleed for the files list issue is reproducable as well. With it I select a file and move to a folder that has no files. It will then read "document.all.fBOOTLOGTXT.innerhtml = " filename.ext " where filename.ext is the last file listed in the "Files selected:" section. Related to this problem, if I go to a folder with no filename (and didn't select a file on the previous folder) the last file listed in the previous folder will be listed as a file in that folder.
The folder one is fixed. I can still cause the file one by selecting a file and opening a folder with no files. document.all.fdesktopini.innerhtml = " desktop.ini " Or if I go to a folder with no files, one file from the previous folder will display in the files list, but the number of files will be 0.
I found the fix for that issue. You just need an ElseIf for an fCount=0.
Only other real issue is the C: drive thing. Doing some msgboxing, my pagefile.sys errors out on the line Execute t. If I do an on error resume next, it shows all the files except pagefile.sys and it duplicates the file before pagefile.sys. Figure that might point you in the right direction for figuring out what the problem is.
I'm glad you have found and fixed a bug in my script because it's a very complicated one! (I always wonder if toher scripters are able to decyphere my scripts)
For the C: drive issue, I think we must add some code specific for working on drives (instead of code specific to folders) but I don't know these codes yet. I can go on C: from any subfolder without error but when I launch it with C: in the arguiment, it starts in the script directory but without error. My Pc run on w98se and it may be diferent on XP.
I won't have time to work on this next week be perhaps in two weeks... :(
I actually wanted to recreate the Common.Dialog box thats available only in Win XP, and I wanted to see if I could use your implementation as a basis to start from. Since I can eat sleep and breath JS a thousand times better than vbs, I figured why not translate it while I peruse it? It be much more intuitive for me to read and alter the code in my first language, not to mention I make it a habit not to mix languages anymore.
_____________________________
To iterate is human, to recurse divine. -- L. Peter Deutsch
TNO, what do you mean exactely by "recreate the Common.Dialog box "?
Reproducing the "open" dialog box graphicaly in generated html code, could be a heavy duty operation, not as fast as my script. If that's what you mean.
For JS is a difficult language,... all these braces floating alone in the middle of the page... you know... ;)