Web Analytics Made Easy -
StatCounter how to get the url of a folder.. urgently need help - CodingForum

Announcement

Collapse
No announcement yet.

how to get the url of a folder.. urgently need help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to get the url of a folder.. urgently need help

    hi guys,, need ur help....

    i facing some problem. at first i thought it was a html problem but my frenz tell me it can be done using javascript.
    that y i hope by posting here can help me...

    i know <input type=file name=try> will display a textbox wif a "browse"btn tat allow user to select a particular file n return the entire path of the file selected in the textbox.

    however, now i want to allow user to select a folder only and return the entire path of the folder.

    therefore the output in the textfield should be
    c:\my document\abc\
    instead of
    c:\my document\abc\text.html


    can anyone tell me how to do so? i need the answer urgently...
    Last edited by jeanieteo; Jul 11, 2002, 09:07 PM.
    jeanie

  • #2
    <input type=file name=try>

    <script>
    var folder = document.formName.try.value;
    folder = folder.slice(0, folder.lastIndexOf('\\') +1)
    alert(folder);
    <script>


    in theory, that will do what you want, but i didn't test it at all.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

    Comment


    • #3
      err.. sorry but i m quite new to javascript.
      i try it out but i got file identifier error.
      may i ask y u never put any action such as onClick or onBlur?

      sorry but do u mind giving me a proper script.. thanks
      jeanie

      Comment


      • #4
        sorry.. but i like to know does it slice after the form is posted or before when the open dialog box is pop out?
        jeanie

        Comment


        • #5
          sorry, didn't realize you were that new.

          <FORM NAME="theForm">
          <input type="file" name="try" onChange="theFunc();">
          </FORM>

          <script>
          function theFunc() {
          var folder = document.theForm.try.value;
          if (/\w+\.\w+$/.test(folder)) {
          folder = folder.slice(0, folder.lastIndexOf('\\') +1);
          }
          if (/\w+\.\w+$/.test(folder)) {
          alert("Your submission seems to have an error in it. Please check to see that there are no typos or mistakes in your submission, and try again. If you continue to have problems, please contact the webmaster.");
          }
          }
          </script>

          what that does, is take the value from the form, and check to see if it matches a certain pattern. that pattern is "one or more word characters (a-zA-Z0-9_)", "a period", "one or more word characaters", "the end of the string". files will match that pattern (because they end with a file name, period, and a file type), but directories will not. if it finds that pattern, it chops off everything after the last '\', which would remove the file name, and leave only the directory. then, it looks for that pattern again. if it finds, then something is wrong, and it alerts the user that something's up.
          bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

          i am a loser geek, crazy with an evil streak,
          yes i do believe there is a violent thing inside of me.

          Comment


          • #6
            Don't use the word "try" as a form name or form item. "try" is a keyword reserved by JavaScript for error handling.

            Here is the corrected code.
            Code:
            <form name=formName>
            
            <input type=file name=tryr onclick="decode()">  
            
            <script> 
            function decode(){
             var folder = document.formName.tryr.value; 
             folder = folder.substr(0, folder.lastIndexOf('\\\') +1) 
             alert(folder); 
             document.formName.tryr.value=folder
            }
            </script>
            
            
            </form>
            [EDIT] Fixed the backslash.

            In theory, the above code does what you're asking, but in reality, browsers act differently.

            In IE6, the "onclick" handler is fired immediately after the user click anywhere on the element.
            In NS4, the event handler is fired after the user selectes a file (more desirable).

            The text in the form element cannot programmatically be changed in either of these browsers.
            Last edited by poccil; Jul 11, 2002, 10:05 PM.

            Comment


            • #7
              is it possible that user juz select a folder than click on open.. so that it need not click on a particular file n then u concat the file name into a folder path?
              jeanie

              Comment


              • #8
                as far as i know, no.
                bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

                i am a loser geek, crazy with an evil streak,
                yes i do believe there is a violent thing inside of me.

                Comment


                • #9
                  then is there anyway to perform a "browse" for folder using html n javascript? hve u come across it?
                  jeanie

                  Comment


                  • #10
                    no. maybe with asp, but not just with html and javascript..
                    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

                    i am a loser geek, crazy with an evil streak,
                    yes i do believe there is a violent thing inside of me.

                    Comment


                    • #11
                      but this is a client side object.. surely it be done using client side scripting language...
                      then can it be done using jsp..

                      thanks alot for replying..
                      jeanie

                      Comment


                      • #12
                        the File input element, is designed to input files, not directories, and there's no Directory input element, so if you want to input a Directory with just HTML and JavaScript, then you hvae to use a File element, and play with it.

                        I have no personal experience with any server side languages. I expect that ASP has some sort of function that will do this, but i don't know for sure. JSP might be able to do it, but again, i don't know.
                        bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

                        i am a loser geek, crazy with an evil streak,
                        yes i do believe there is a violent thing inside of me.

                        Comment


                        • #13
                          if you use server-side language, you can access the directories of the server NOT the client.
                          So, browsing for folders in the client cannot be done either with pure javascript or ASP/JSP or any server-side language for that matter.

                          you may have to use an ActiveX control to be able to do that.
                          don't know if there's an existing control for that or you may have to create one.
                          Glenn
                          vBulletin Mods That Rock!

                          Comment


                          • #14
                            I just found this and thought I'd add it to the thread

                            <html>
                            <head>
                            <title></title>
                            <script>

                            function Browse_For_Folder_Dialogue() {
                            var objShell = new ActiveXObject("Shell.Application");
                            var objFolder = new Object;
                            objFolder = objShell.BrowseForFolder(0, "Select folder", 0);
                            if (objFolder == null) {
                            return
                            } else {
                            var objFolderItem = new Object;
                            objFolderItem = objFolder.Items().Item();
                            alert(objFolderItem.Path)
                            }
                            }


                            onload = function() {
                            Browse_For_Folder_Dialogue()
                            }

                            </script>
                            </head>
                            <body>
                            </body>
                            </html>


                            There is a 4th argument, see here



                            and here

                            Comment

                            Working...
                            X