How to get current ASP script running file name without using FileSystem object

We can get the current file name of the asp script without using the FileSystem object. The reason for this is we want to develop a common script which can be used ( or included ) in any file to display various file system properties. The FileSystem object needs the file name as input so we will try to develop this script which can be used as a input to the FileSystem object for further development.

The best example is to develop a script which will display the last modified date of the file. Let us start with how to read the script name in ASP. The code used below will give the file name along with the directory or the path name.

Dim my_array, fname
fname = Request.ServerVariables("SCRIPT_NAME")

The above code will display the file name with full path. For example if the present file is in my_file directory and file name is test.asp then the output will be


To get the file name out of the above full path string we have to break the string and create an array by using split function with / as delimiter. Once the array is created we can get the last element of the array to get the file name. Here we will be using Ubound function to get the size of the array and we will use that to get the last element of the array.

Here is the full code to display the current file name

Dim my_array, fullname, fname
Response.Write Request.ServerVariables("SCRIPT_NAME") & "<br>"
fullname = Request.ServerVariables("SCRIPT_NAME")
Response.Write fname

Number of User Comments : 2



Or to make it even easier just do this... ScriptName = Request.ServerVariables("script_name") ScriptName = Right(ScriptName, Len(ScriptName) - InStrRev(ScriptName, "/"))


Even easier
ScriptName = Request.ServerVariables("script_name")
ScriptName = Mid(ScriptName, InStrRev(ScriptName, "/") + 1)

Post your comments , suggestion , error , requirements etc here .

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2021 All rights reserved worldwide Privacy Policy Disclaimer