Did you find this useful?
Socialize it today.

ASP File Object

Saturday, September 15, 2012

tags ASP

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:


AttributesSets or returns the attributes of the specified file.
DateCreatedReturns the date and time that the specified file was created.
DateLastAccessedReturns the date and time that the specified file was last accessed.
DateLastModifiedReturns the date and time that the specified file was last modified.
DriveReturns the drive letter of the drive on which the specified file or folder resides.
NameSets or returns the name of the specified file.
ParentFolderReturns the Folder object for the parent folder of the specified file.
PathReturns the absolute path of the specified file.
ShortNameRreturns the 8.3 name of the file name.
ShortPathReturns the 8.3 name of the absolute path of the specified file.
SizeReturns the size of the specified file.
TypeReturns the type of the specified file.


CopyCopies the specified file from one folder to another.
DeleteDeletes the specified file.
MoveMoves the specified file from one folder to another.
OpenAsTextStreamOpens the specified file and returns a TextStream object that can be used to read from, write to, or append to the file.


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")
Set objFile=nothing
Set objFSO=nothing

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.

Recommended Books & Training Resources

ASP In A Nutshell Beginning ASP Databases Sams Teach Yourself Active Server Pages 3.0 in 21 Days