Browse directories instead of files

with <input type="file"> i browse files, and get back their pathes,
i would like to browse directories and get their path back, can i do that?

also i seem to have problems accessing files that are under C:/Documents And Settings/username/
is there a way to access it?
LVL 1
tomerbarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

azcn2503Commented:
Is this the kind of thing you're looking for...

<script type="text/javascript"><!--

      function parsefile(val){
      
            val=val.split("\\");
            
            tval="";
            
            for(i=0;i<val.length-1;i++){
            
                  tval+=val[i]+"\\";
            
            }
            
            return tval;
      
      }

//--></script>

<input type="file" onchange="alert(parsefile(this.value));">



Aaron.
COBOLdinosaurCommented:
The input file is restrict to a single file security limitations prevent it form being scripted.  The security is there to help orotect users from malicious sites that could use exploits off othe cntrol to steal files and sesitive data if the security was not in place.

If you want to explain what you are trying to accomplish oan post your code, we may be able to come up with alternatives; but under no circumstances will code to bypass security on the input file control be permitted on this site.

Cd&
kiddangerCommented:
You could do it with an HTA, which would bypass the security but the HTA would have to be accepted by the user.  As Cd& suggested, providing detail of your application will most likely give you better response towards reaching your goal.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

COBOLdinosaurCommented:
HTA does not bypass security, it is just a looser model that assumes a more intelligent user, and puts the decisions in their hands instead of defaul browser behaviours.

Cd&


kiddangerCommented:
It bypasses the default security restrictions of browsers.

<input type="file" /> has certain security restrictions.  HTA's are not subject to browser security.

From:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/hta/overview/htaoverview.asp

In short, HTAs pack all the power of Internet Explorer—its object model, performance, rendering power, protocol support, and channel-download technology—without enforcing the strict security model and user interface of the browser.
...
HTAs are not subject to the same security constraints as Web pages.
...
HTAs are suited to many uses, whether you are prototyping, making wizards, or building full-scale applications. Whatever DHTML and script deliver now—forms, multimedia, Web applications, HTML editors, and browsers—so can HTAs...and then some.
tomerbarAuthor Commented:
Well mu idea is to list files from a directory on the page and displaying them on the html right from the edge user's hard drive. all the user needs to do is give a directory.
kiddangerCommented:
A server does not have the rights to list anything on a client.  type="file" runs on the client, even if the page is read from the server, the server just serves the HTML page.  It has no control over its use.

You will need something on the client other than type="file".  That can be an ActiveX component or you could use an HTA, which the client would have to accept to download/run.
tomerbarAuthor Commented:
what is an HTA?
COBOLdinosaurCommented:
Have fun kid ;^)

Cd&
kiddangerCommented:
CD&...

That's why we're here!

tomerbar...

The link I provided is where you would start learning about HTA's.  HTA = HTML Application.  The link will open up into a frame and on the left below the current reference is a link for references.  Click on the + and it will expand to Object, Attributes and Properties.  HTAs are not difficult, they're actually quite easy to work with just different than what you're used to but you can still use vbscript as you have in the past.

You could write your own directory recurse of a given path or just get a list of folders easily using FSO.  With an ASP page, you can only do this on the server.  Now you can do it on the client.  It's the same code.

This should get you started.

iebrowse.hta

<html>
<head>
<title></title>
<script type="text/vbscript">
sub bbrowse_onclick()
 goIE
end sub

function  folderlist(strPath)
  dim fso, f
  set fso = CreateObject("Scripting.FileSystemObject")
  set f = fso.GetFolder(strPath)
  set folderlist = f.subfolders
  set folder = nothing
  set fso = nothing
end function

sub goIE()
  dim fc, folder
  set fc = folderlist("c:\Documents and Settings")
  Set IE = CreateObject("InternetExplorer.Application")
  IE.visible = true
  IE.Navigate("about:blank")
  Do Until IE.ReadyState = 4
  Loop
    IE.document.write "<html>" & vbCrLf
    IE.document.write "<head>" & vbCrLf
    IE.document.write "<script type='text/javascript'>" & vbCrLf
    IE.document.write "function showFolder(f) {" & vbCrLf
    IE.document.write "  var t = document.getElementById('div1');" & vbCrLf
    IE.document.write "  t.innerHTML=f;" & vbCrLf
    IE.document.write "  t.style.display=='none' ? t.style.display='block' : null;" & vbCrLf
    IE.document.write "  }" & vbCrLf
    IE.document.write "</scr" & "ipt>" & vbCrLf
    IE.document.write "</head>" & vbCrLf
    IE.document.write "<body>" & vbCrLf
    IE.document.write "<div id='div1' style='display: none; background-color: #efe; border: 1px solid black'></div><br />" & vbCrLf
    IE.document.write "<select name='select1' onchange=""showFolder(this[this.selectedIndex].value)"">" & vbCrLf
    IE.document.write "<option selected></option>" & vbCrLf
  for each folder in fc
    IE.document.write "<option value='" & folder & "'>" & folder & "</option>" & vbCrLf
  next
  with IE
    .document.write "</select>" & vbCrLf
    .document.write "</body>" & vbCrLf
    .document.write "</html>" & vbCrLf
  end with
end sub
</script>

</head>
<body>

<INPUT NAME="bbrowse" TYPE="button" TITLE="Browse to select file." VALUE="Folders" /><BR />
</body>
</html>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kiddangerCommented:
Thank you tomer.
COBOLdinosaurCommented:
>>>That's why we're here!

Give a man a fish and he eats for a day... teach him how to fish and eats for a lifetime.

You didn't teach a thing except the definition of an HTA.  

All you did was make them dependent on you to write the code for them.

If all you can do is take the easy way, you'll never be anywhre near the top of that list on the left side of the page.  You've got enough talent to be more than a code monkey.  There are a million coders in the world who can write that code, but only a tiny percentage of them can teach some else to write it for themselves.

Cd&
kiddangerCommented:
CD&

"You didn't teach a thing except the definition of an HTA."

The question was: "what is an HTA?"

"All you did was make them dependent on you to write the code for them."

Actually I only wrote part of it.  If he wants to recurse the subdirectories, he'll need more code.  Perhaps you missed this: "This should get you started."

So, I took him fishing and gave him my catch.  Now he knows a little bit about fishing and if he wants to continue to eat, he'll have to catch some on his own.  Pointing someone to documentation is not teaching them anything.  Might as well just say RTFM!  BTW, I also pointed him to the documentation.

"If all you can do is take the easy way, you'll never be anywhre near the top of that list on the left side of the page."

I'm here to help people.  I thought that was the goal of this site.  I'm not just trying to make a name for myself.  I have a lot of expertise and I'm pretty well known, in certain circles.  I also learn something from each person I try to help and some appreciate it.  If someone doesn't understand anything, I expect them to ask for help or an explanation.

Seeing a working example when you're not familiar with something goes a lot further than just trying to figure out the documentation, which is not always perfect and which sometimes is prone to having errors.  HTAs are not that difficult but a little overwhelming the first time.  I tried to minimize the effect.

I'm not a code monkey and I don't appreciate the term, although I know it was not meant to be malicious.  I am first and foremost and network security professional.  I also happen to develop in almost 30 languages and right now I'm making more money doing that.  I believe the best way to teach someone is to show them.  I don't know what they know/don't know.  If they don't follow up, then perhaps they'll starve but I have found usually it gets them to ask more questions and thus the learning experience continues.
COBOLdinosaurCommented:
First of all if code monkey was taken as an insult; I appologize that is how most of my coders refer to themselves (you don't want know how they refer to me).

Secondly, I was not looking to trigger an aggresive response; I was trying to get you to look at how you are responding in a different way.  Experts who just drop the answers tend to get bored and leave; or at least reduce active participation.  The Web TAs are thin staffed, and I was just looking to get you to try something that might hold your interest longer.

What ever way you want to do things is fine; but don't automatically think you are being attack when someone makes a suggest, even if it is as badly presented as mine sometimes are.  There is a mix of languages and cultures on this site and it is easy to misunderstand and be misunderstood when words do not always deliver the intended message.

Cd&
kiddangerCommented:
Cd&...

No problem.  We're cool.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.