在Classic ASP中写出文件/页面名称

时间:2012-05-02 15:11:29

标签: asp-classic

假设我有这样的网址:http://website.com/folder/myfile.asp

如何制作仅写出的脚本:“myfile.asp”

3 个答案:

答案 0 :(得分:5)

这是所需的代码。

<%

     Dim arrPath: arrPath = Split(Request.ServerVariables("SCRIPT_NAME"), "/")

     Dim fileName: fileName = arrPath(UBound(arrPath))
%>

获取当前脚本URL路径中的元素数组,然后选择该数组中最后一个元素作为文件名。

现在,如果您希望在ASP / VBScript中做任何重要工作,我建议您花些时间阅读所有与VBScript here相关的内容。那里没有大量的信息,但花费的时间会很快收回。

答案 1 :(得分:0)

使用此:

<% = Request.ServerVariables("SCRIPT_NAME") %>

答案 2 :(得分:0)

这里有一个简单的功能

<%

 Function getFileName(lsPath)

  ' Obtain the virtual file path '
  lsPath = Request.ServerVariables("SCRIPT_NAME")

  ' Split the path along the /s. This creates a one-dimensional array '

  arPath = Split(lsPath, "/")

  ' The last item in the array contains the file name '

  GetFileName =arPath(UBound(arPath,1))

 End Function

%>

<%=getFileName(Request.ServerVariables("SCRIPT_NAME"))%>
相关问题