ASP File



The File object is used to return information about the specified file.


tryitimg.gif

Try it - Example

When was the file last modified?
This example demonstrates how to use the DateLastModified attribute to obtain the date and time the specified file was last modified.

When was the file last accessed?
This example demonstrates how to use the DateLastAccessed property to obtain the date and time the specified file was last accessed.

Return the attributes of the specified file
This example demonstrates how to use Attributes to return the attributes of the specified file.


File Object

The File object is used to return information about the specified file.

To operate the related properties and methods of the File object, you need to create an instance of the File object through the FileSystemObject object. First, create a FileSystemObject object, and then instantiate the File object through the GetFile method of the FileSystemObject object, or through the Files property of the Folder object.

The following code uses the GetFile method of the FileSystemObject object to instantiate the File object, and uses the DateCreated property to return the creation date of the specified file:

Example

<%
Dim fs,f
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.GetFile("c:\test.txt")
Response.Write("File created: " & f.DateCreated)
set f=nothing
set fs=nothing
%>

Run Instance»

Click the "Run Instance" button to view the online instance

The properties and methods of the File object are described as follows:

Properties

PropertiesDescription
AttributesSet or return the attributes of the specified file.
DateCreated Returns the date and time the specified file was created.
DateLastAccessedReturns the date and time the specified file was last accessed.
DateLastModifiedReturns the date and time the specified file was last modified.
Drive Returns the drive letter of the drive where the specified file or folder is located.
NameSet or return the name of the specified file.
ParentFolderReturns the parent folder object of the specified file.
PathReturns the path of the specified file.
ShortName Returns the short name of the specified file (8.3 naming convention).
ShortPathReturns the short path to the specified file (8.3 naming convention).
SizeReturns the size (bytes) of the specified file.
TypeReturns the type of the specified file.

Method

MethodDescription
CopyCopy the specified file from one location to another.
DeleteDelete the specified file.
MoveMove the specified file from one location to another.
OpenAsTextStreamOpens the specified file and returns a TextStream object to access this file.