Click to See Complete Forum and Search --> : how to get the url of a folder.. urgently need help


jeanieteo
July 11th, 2002, 08:37 PM
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...

goddess_spanky
July 12th, 2002, 10:09 AM
I don't know how you could easily do this with JavaScript, but it would be very easy using VBScript. The only problem with that is VBScript only works in IE (client-side).
If you are doing server-side scripting (ASP page using VBScript) then I can give you simple way to do this using the FileSystemObject.
Let me know exactly how your page is setup (HTML/JavaScript or ASP/VBScript) & I'll see what I can do.

jeanieteo
July 14th, 2002, 07:39 PM
thanks a lot...
but i dun know whether vbscript will work for me a not..
actually my coding is using jsp( java server page).
i use pure html with javascript.. in a form which i post it to a jsp file to do the backend servicing.
i m using tomcat webserver 3.3.1.
so can vbscript be like javascript tat can be executed in jsp pages..

thanks for replying.. hope u can reply me soon..

Zvona
July 15th, 2002, 02:56 AM
Guess this is what you're after :
<!-- Example Written by Zvona -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Parsing a folder</title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1;" />
<script type="text/javascript">
<!--
function getFolderNames(oForm)
{
var iA = 0;
var aInputF = new Array();
var aReturnVal = new Array();
for (var iI=0;iI<oForm.length;iI++)
{
if (oForm.elements[iI].type == "file")
{
aInputF[iA] = oForm.elements[iI];
iA++;
}
}

for (var iI=0;iI<aInputF.length;iI++)
{
if (aInputF[iI].disabled || aInputF[iI].value == "")
aReturnVal[iI] = "No folder";
else
aReturnVal[iI] = aInputF[iI].value.substring(0,aInputF[iI].value.lastIndexOf("\\"));
}

return aReturnVal;
}
// -->
</script>
</head>

<body>
<form action="">
<table border="0">
<tbody>
<tr>
<td><input type="file" /></td>
</tr>
<tr>
<td><input type="file" /></td>
</tr>
<tr>
<td><input type="file" /></td>
</tr>
<tr>
<td><input type="button" value="getFolderNames()" onclick="alert(getFolderNames(this.form));" /></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Tested with NN4.7 & IE6. Blue function is the one you need. It returns the value in an array.