SQL PHP HTML ASP JavaScript articles and free scripts to download
 

How to get last updated & created date and time of an ASP file


We will try to develop a code for showing the last modified date and the created date of the file and display to visitors. This code has to work on it own without any input or changed settings.

We will use the FileSystemObject for getting the last changed or updated along with created date of the file. To make this code universal we will not use name of the file as input to this FileSystemObject , it its place we will use code to get the current file name and then use that as input to FileSystemObject. This way we can make it independent of file name setting and the same code can be used inside any asp file without any changes.

Before reading this it is advisable to read the FileSystemObject and how to get the file name of the current script running page. With this knowledge we can add more code to get the last updated time of the file.

Here is the code to get the current file name and FileSystemObject created.

Dim objFSO, objFile, fname, fullname, my_array
fullname = Request.ServerVariables("SCRIPT_NAME")
my_array=split(fullname,"/")
fname=my_array(ubound(my_array))

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(Server.MapPath(fname))


To these lines we will add the file name and DateCreated and DateLastModified to get the full code to display the modified time.

Response.Write "Created date of file "& objFile.Name & " = " & objFile.DateCreated Response.Write "
Last Modified date of file "& objFile.Name & " = " & objFile.DateLastModified


Note that the above code can be used in any asp file without any modification to get the last updating and creating date and time of the file. Similar code to get the last modified date and time can be developed using PHP script.
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.