ASP 文件对象


File 对象用于返回有关指定文件的信息。


更多示例

文件最后一次修改是什么时候?
如何获取指定文件的上次修改日期和时间。

上次访问文件是什么时候?
如何获取上次访问指定文件的日期和时间。

返回指定文件的属性
如何返回指定文件的属性。


文件对象

File 对象用于返回有关指定文件的信息。

要使用 File 对象的属性和方法,您必须通过 FileSystemObject 对象创建 File 对象的实例。第一的;创建一个FileSystemObject 对象,然后通过FileSystemObject 对象的GetFile 方法或通过Folder 对象的Files 属性实例化File 对象。

以下代码使用 FileSystemObject 对象的 GetFile 方法实例化 File 对象,并使用 DateCreated 属性返回创建指定文件的日期:

示例

<%
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
%>
显示示例 »


File对象的属性和方法描述如下:

特性

Property Description
Attributes Sets or returns the attributes of a specified file
DateCreated Returns the date and time when a specified file was created
DateLastAccessed Returns the date and time when a specified file was last accessed
DateLastModified Returns the date and time when a specified file was last modified
Drive Returns the drive letter of the drive where a specified file or folder resides
Name Sets or returns the name of a specified file
ParentFolder Returns the folder object for the parent of the specified file
Path Returns the path for a specified file
ShortName Returns the short name of a specified file (the 8.3 naming convention)
ShortPath Returns the short path of a specified file (the 8.3 naming convention)
Size Returns the size, in bytes, of a specified file
Type Returns the type of a specified file

方法

Method Description
Copy Copies a specified file from one location to another
Delete Deletes a specified file
Move Moves a specified file from one location to another
OpenAsTextStream  Opens a specified file and returns a TextStream object to access the file