SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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

Further readings
Server.MapPath to convert virtual path to physical path of files and directory.
FileSystemObject:Checking file or folder exist by using File system object .
Getting the file name from full path of the current running script in ASP.
Getting the file extension and file name by using FSO
Deleting file by using DeleteFile in FSO
Getting the Last updating and creation date and time of a file.
Listing all files present inside a folder using FileSystemObject
Reading data from a text file using File System Object
Writing data to a text file using File System Object
Read & Writing data to a text file: Developing a page hit counter
Appending data to a text file: Storing emails in a text file
Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
All ASP Tutorials
File Management
MapPath
FileSystemObject
append
name
Updating Time
Listing all files
Reading file
Writing file
Read & Write
File type
Delete File
ASP Sections
Ajax
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
String Functions
Popular Tutorials
Managing two drop downs
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.