ASP File
The File object is used to return information about the specified file.
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
Properties | Description |
---|---|
Attributes | Set or return the attributes of the specified file. |
DateCreated | Returns the date and time the specified file was created. |
DateLastAccessed | Returns the date and time the specified file was last accessed. |
DateLastModified | Returns 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. |
Name | Set or return the name of the specified file. |
ParentFolder | Returns the parent folder object of the specified file. |
Path | Returns the path of the specified file. |
ShortName | Returns the short name of the specified file (8.3 naming convention). |
ShortPath | Returns the short path to the specified file (8.3 naming convention). |
Size | Returns the size (bytes) of the specified file. |
Type | Returns the type of the specified file. |
Method
Method | Description |
---|---|
Copy | Copy the specified file from one location to another. |
Delete | Delete the specified file. |
Move | Move the specified file from one location to another. |
OpenAsTextStream | Opens the specified file and returns a TextStream object to access this file. |