日期:2010-01-21  浏览次数:20703 次

Server 对象
此文件最后被修改的时间是?

探测文件的最后更新时间。

本示例代码如下:

<html>
<body>
<%
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set rs = fs.GetFile(Server.MapPath("/example/aspe/demo_aspe_lastmodified.asp"))
modified = rs.DateLastModified
%>
本文件的最后修改时间是:<%response.write(modified)
Set rs = Nothing
Set fs = Nothing
%>
</body>
</html>

本实例运行结果如下:

本文件的最后修改时间是:2009-2-21 20:42:29

打开并读取某个文本文件

本例会打开文件"Textfile.txt"以供读取。

本示例代码如下:

<html>
<body>
<%
Set FS = Server.CreateObject("Scripting.FileSystemObject")
Set RS = FS.OpenTextFile(Server.MapPath("/example/aspe") & "\textfile.txt",1)
While not rs.AtEndOfStream
      Response.Write RS.ReadLine
      Response.Write("<br />")
Wend
%>
<p>
<a href="/example/aspe/textfile.txt">查看此文本文件</a>
</p>
</body>
</html>

本实例运行结果如下:

Hello World line 1
Hello World line 2
Hello World line 3
查看此文本文件

此文本文件内容是:

Hello World line 1
Hello World line 2
Hello World line 3

自制的点击计数器

本例可从某文件中读取一个数字,并在此数字上累加1,然后将此数写回这个文件。

本示例代码如下:

<%
Set FS=Server.CreateObject("Scripting.FileSystemObject")
Set RS=FS.OpenTextFile(Server.MapPath("/example/aspe/counter.txt"), 1, False)
fcount=RS.ReadLine
RS.Close
fcount=fcount+1
'This code is disabled due to the write access security on our server:
'Set RS=FS.OpenTextFile(Server.MapPath("counter.txt"), 2, False)
'RS.Write fcount
'RS.Close
Set RS=Nothing
Set FS=Nothing
%>
<html>
<body>
<p>
本页已被访问了 <%=fcount%>  次。
</p>
</body>
</html>

本实例运行结果如下:

本页已被访问了 12 次。