ASP File Object
- Previous Page ASP Drive
- Next Page ASP Folder
The File object is used to return information about a specified file.
Example
- When was this file created?
- This example demonstrates how to first create a FileSystemObject object, and then use the File object's DateCreated attribute to obtain the date and time a specified file was created.
- When was this file last modified?
- This example demonstrates how to use the DateLastModified attribute to obtain the date and time a specified file was last modified.
- When was this file accessed?
- This example demonstrates how to use the DateLastAccessed property to obtain the date and time when the specified file was last accessed.
- Return the attributes of the specified file
- This example demonstrates how to use the 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 on the properties and methods of the File object, we need to create an instance of the File object through the FileSystemObject. First, create a FileSystemObject object, and then use the GetFile method of the FileSystemObject object, or use the Files property of the Folder object to create an instance of this File object.
The following code demonstrates how to use the GetFile method of the FileSystemObject object to create an instance of the File object and use the DateCreated property to return the date when the specified file was created:
<% 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 %>
Output:
File created: 8/8/2008 10:01:19 AM
Properties and methods of the File object
Attributes
Attributes | Description |
---|---|
Attributes | Set or return the attributes of the specified file. |
DateCreated | Return the date and time when the specified file was created. |
DateLastAccessed | Return the date and time when the specified file was last accessed. |
DateLastModified | Return the date and time when the specified file was last modified. |
Drive | Return 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 | Return the parent folder object of the specified file or folder. |
Path | Return the path of the specified file. |
ShortName | Return the short name of the specified file (8.3 naming convention). |
ShortPath | Return the short path of the specified file (8.3 naming convention). |
Size | Return the size of the specified file (in bytes). |
Type | Return the type of the specified file. |
Method
Method | Description |
---|---|
Copy | Copy a specified file from one location to another. |
Delete | Delete a specified file. |
Move | Move a specified file from one location to another. |
OpenAsTextStream | Open a specified file and return a TextStream object to access this file. |
- Previous Page ASP Drive
- Next Page ASP Folder