The ASP File object is used to access a specified file on a computer. The File object has properties and methods that you to access the file. First, create an instance of the FileSystemObject object and then instantiate the File object
through the GetFile method. File object properties and methods are as follows:
Properties
Property | Description |
Attributes | Sets or returns the attributes of the specified file. |
DateCreated | Returns the date and time that the specified file was created. |
DateLastAccessed | Returns the date and time that the specified file was last accessed. |
DateLastModified | Returns the date and time that the specified file was last modified. |
Drive | Returns the drive letter of the drive on which the specified file or folder resides. |
Name | Sets or returns the name of the specified file. |
ParentFolder | Returns the Folder object for the parent folder of the specified file. |
Path | Returns the absolute path of the specified file. |
ShortName | Rreturns the 8.3 name of the file name. |
ShortPath | Returns the 8.3 name of the absolute path of the specified file. |
Size | Returns the size of the specified file. |
Type | Returns the type of the specified file. |
Methods
Method | Description |
Copy | Copies the specified file from one folder to another. |
Delete | Deletes the specified file. |
Move | Moves the specified file from one folder to another. |
OpenAsTextStream | Opens the specified file and returns a TextStream object that can be used to read from, write to, or append to the file. |
Examples
In the following example we will create an instance of the FileSystemObject object and then use the GetFile method to instantiate the File object. Finally, we use The File object properties to get the information about the specified file.
The second example shows how to delete a file.
<%
Dim objFSO, objDrive
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\temp\test.txt")
Response.Write("Name: " & objFile.Name & "<br />")
Response.Write("ShortName: " & objFile.ShortName & "<br />")
Response.Write("Size: " & objFile.Size & " bytes <br />")
Response.Write("Type: " & objFile.Type & "<br />")
Response.Write("Path: " & objFile.Path & "<br />")
Response.Write("ParentFolder: " & objFile.ParentFolder & "<br />")
Response.Write("ShortPath: " & objFile.ShortPath & "<br />")
Response.Write("DateCreated: " & objFile.DateCreated & "<br />")
Response.Write("DateLastAccessed: " & objFile.DateLastAccessed & "<br />")
Response.Write("DateLastModified: " & objFile.DateLastModified)
%>
<%
Dim objFSO,objFile
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.GetFile("c:\temp\test.txt")
objFile.Delete
Set objFile=nothing
Set objFSO=nothing
%>
Did you find the page informational and useful? Share it using one of your favorite social sites.
Recommended Books & Training Resources