getting file Name

L

Laurent

Hi all,

I'm searching to find the name of the file in which i execute a script.

example : i'm into /directory/page.asp

and i d like to know which variable could help me to find the path of the
file on server side.

thanks a lot and have a nice day


Laurent
http://www.chazallet.com
 
D

Dave Anderson

Laurent said:
I'm searching to find the name of the file in which i execute a
script.

example : i'm into /directory/page.asp

and i d like to know which variable could help me to find the
path of the file on server side.

Here's one JScript way of doing it:

function showServerVariables() {
var v = Request.ServerVariables
e = new Enumerator(v),
a = new Array(),
s = new String()
for (; !e.atEnd(); e.moveNext()) {
s = String(e.item())
if (!/^ALL/.test(s))
a.push(
"<TD><B>" + s + "</B></TD>" +
"<TD>" + split(v(s)) + "</TD>"
)
}

return "<TABLE><TR VALIGN=\"top\">" +
a.join("</TR>\r\n<TR VALIGN=\"top\">") +
"</TR>\r\n</TABLE>"

function split(item) {
item = String(item)
return item.replace(
/([;\n])/g,"$1<BR>"
).replace(
/(,)/g,"$1 "
).replace(
/(&)/g,"&<BR>&nbsp;&nbsp;&nbsp;"
)
}
}

<%=showServerVariables()%>


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
B

Bob Lehmann

WOW! And to think it could have been done in only 3 lines instead.

Nice job.

Bob Lehmann
Verbose, overly-complex code will be read at a cost of $500 per line.

Dave Anderson said:
Laurent said:
I'm searching to find the name of the file in which i execute a
script.

example : i'm into /directory/page.asp

and i d like to know which variable could help me to find the
path of the file on server side.

Here's one JScript way of doing it:

function showServerVariables() {
var v = Request.ServerVariables
e = new Enumerator(v),
a = new Array(),
s = new String()
for (; !e.atEnd(); e.moveNext()) {
s = String(e.item())
if (!/^ALL/.test(s))
a.push(
"<TD><B>" + s + "</B></TD>" +
"<TD>" + split(v(s)) + "</TD>"
)
}

return "<TABLE><TR VALIGN=\"top\">" +
a.join("</TR>\r\n<TR VALIGN=\"top\">") +
"</TR>\r\n</TABLE>"

function split(item) {
item = String(item)
return item.replace(
/([;\n])/g,"$1<BR>"
).replace(
/(,)/g,"$1 "
).replace(
/(&)/g,"&<BR>&nbsp;&nbsp;&nbsp;"
)
}
}

<%=showServerVariables()%>


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
D

Dave Anderson

Bob said:
WOW! And to think it could have been done in only 3 lines instead.

Or two:
for (var v=Request.ServerVariables,e=new
Enumerator(v),a=[],s="";!e.atEnd();e.moveNext()){s=String(e.item());a.push("
["+s+"] "+v(s))}
<%=a.join("<BR>")%>

Why not one?
<%=Request.ServerVariables%>



Of course, neither of these breaks out the cookies and their keyed
name/value pairs into separate line items as my posted example does.

But I suppose you think an example must be written anew each time a question
is to be answered, rather than lifted from any utility scripts we may have
lying around. I confess I am not fond of leaving markup in my examples, but
I considered it relevant in this case.


Nice job.

Bob Lehmann
Verbose, overly-complex code will be read at a cost of $500 per line.

Whatever. If push/join/replace is complex, then sue me.

function showServerVariables() {
var v = Request.ServerVariables,
e = new Enumerator(v),
a = new Array(),
s = new String()
for (; !e.atEnd(); e.moveNext()) {
s = String(e.item())
if (!/^ALL/.test(s))
a.push(
"<TD><B>" + s + "</B></TD>" +
"<TD>" + split(v(s)) + "</TD>"
)
}

return "<TABLE><TR VALIGN=\"top\">" +
a.join("</TR>\r\n<TR VALIGN=\"top\">") +
"</TR>\r\n</TABLE>"

function split(item) {
item = String(item)
return item.replace(
/([;\n])/g,"$1<BR>"
).replace(
/(,)/g,"$1 "
).replace(
/(&)/g,"&<BR>&nbsp;&nbsp;&nbsp;"
)
}
}

<%=showServerVariables()%>


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top