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
/my_file/test.asp
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")
my_array=split(fullname,"/")
fname=my_array(ubound(my_array))
Response.Write fname
This article is written by plus2net.com team.
Number of User Comments : 2
plus2net.com
|