ASP Tutorials - Finding file properties using the File System Object
The File System Object can return a file object and this has a number of sub properties which can be read.
The File System Object can return a file object and this has a number of sub properties which can be read.
The following example lists the file properties found by the File System Object. It uses a physical path to the file.
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set AFile = FSO.GetFile(Server.MapPath("somefile.asp"))
Response.Write "Attributes: " & AFile.Attributes & "<br>"
Response.Write "Date Created: " & AFile.DateCreated & "<br>"
Response.Write "Date Last Accessed: " & AFile.DateLastAccessed & "<br>"
Response.Write "Date Last Modified: " & AFile.DateLastModified & "<br>"
Response.Write "Drive: " & AFile.Drive & "<br>"
Response.Write "Name: " & AFile.Name & "<br>"
Response.Write "Parent Folder: " & AFile.ParentFolder & "<br>"
Response.Write "Path: " & AFile.Path & "<br>"
Response.Write "Size: " & AFile.Size & "<br>"
Response.Write "Type: " & AFile.Type & "<br>"
Server.MapPath is used to find the physical path of somefile.asp, but the physical path could have been hard coded, or a variable containing the path to the file could have been used.
Most of the properties are self explanatory. The file size is in bytes. The attributes are a byte value where each bit provides some information. The bit values are: Normal - 0, Read only - 1, Hidden - 2, System - 4, Volume - 8, Directory - 16, Archive - 32, Alias - 64, Compressed - 128. For example, a hidden, system file would have an attribute value of 6 (2 + 4).
The sample code in these tutorials is written for VBScript in classic ASP unless otherwise stated. The code samples can be freely copied.
© Chestysoft, 2024.