The File object represents a specified file on the local machine or on a network share. To work with the File object’s properties and methods, you need to create an instance of the FileSystemObject object first and then instantiate the File object through the GetFile method. Also you can get a File object reference from the Folder object, by using the Files Collection.
The File object properties and methods are as follows:
|Attributes||The Attributes property sets or returns (depending on the specific file attribute) the attributes of the specified file.|
|DateCreated||The DateCreated property returns the date and time that the specified file was created.|
|DateLastAccessed||The DateCreated property returns the date and time that the specified file was last accessed.|
|DateLastModified||The DateCreated property returns the date and time that the specified file was last modified. It refers to the most recent date the file was altered, not simply opened or examined.|
|Drive||The Drive property returns the drive letter of the drive on which the specified file or folder resides.|
|Name||The Name property sets or returns the name of the specified file.|
|ParentFolder||The ParentFolder returns the Folder object for the parent folder of the specified file.|
|Path||The Path property returns the absolute path of the specified file.|
|ShortName||The ShortName property returns the DOS-style version of the file name (the 8.3 naming convention).|
|ShortPath||The ShortPath property returns the DOS-style version of the absolute path of the specified file (the 8.3 naming convention).|
|Size||The Size property returns the size of the specified file (in bytes).|
|Type||The Type property returns the type of the specified file, as determined using your machine’s file associations (if one exists). For example, on a machine with Microsoft Access installed, the file examples.mdb would have a Type property of Microsoft Office Access Application.|
|Copy||The Copy method copies the specified file from one folder to another.|
|Delete||The Delete method deletes the specified file.|
|Move||The Move method moves the specified file from one folder to another.|
|OpenAsTextStream||The OpenAsTextStream method opens the specified file and returns a TextStream object that can be used to read from, write to, or append to the file.|
How to use the ASP File Object
In the following example we create an instance of the FileSystemObject object and then use the GetFile method to instantiate the File object. After that we use The File object properties to get the information about the specified file:
Dim objFSO, objDrive
'Create a FileSystemObject instance
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Using the GetFile method of FileSystemObject object, initialize a File object
Set objFile = objFSO.GetFile("c:\test.txt")
'Retrieve information about the file
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 "ShortPath: " & objFile.ShortPath & "<br />"
Response.Write "Created: " & objFile.DateCreated & "<br />"
Response.Write "LastModified: " & objFile.DateLastModified & "<br /><br />"