Latest web development tutorials

ASP File objects

File object is used to return information about the specified file.


Examples

Try - Example

The file was last modified time?
This example demonstrates how to use the DateLastModified property to get the date and time the specified file was last modified.

The file was last accessed time?
This example demonstrates how to use DateLastAccessed property to get the date and time the specified file was last accessed.

Returns properties of the specified file
This example demonstrates how to use the Attributes property to return the specified file.


File objects

File object is used to return information about the specified file.

For properties and methods related to the operation of the File object, you need to create an instance of the File object through the FileSystemObject object. First, create a FileSystemObject object and then by GetFile method of the FileSystemObject object, or property through the Files Folder object to instantiate the File object.

The following code uses the FileSystemObject object GetFile method to instantiate File object and DateCreated property to return a specified file creation date:

Examples

<%
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
%>

The demonstration >>

File object properties and methods are described below:

Attributes

属性 描述
Attributes 设置或返回指定文件的属性。
DateCreated 返回指定文件被创建的日期和时间。
DateLastAccessed 返回指定文件最后被访问的日期和时间。
DateLastModified 返回指定文件最后被修改的日期和时间。
Drive 返回指定文件或文件夹所在的驱动器的驱动器字母。
Name 设置或返回指定文件的名称。
ParentFolder 返回指定文件的父文件夹对象。
Path 返回指定文件的路径。
ShortName 返回指定文件的短名称(8.3 命名约定)。
ShortPath 返回指定文件的短路径(8.3 命名约定)。
Size 返回指定文件的尺寸(字节)。
Type 返回指定文件的类型。

method

方法 描述
Copy 把指定文件从一个位置拷贝到另一个位置。
Delete 删除指定文件。
Move 把指定文件从一个位置移动到另一个位置。
OpenAsTextStream 打开指定文件,并返回一个 TextStream 对象来访问此文件。