此檔案最後被修改的時間是?探測檔案的最後更新時間。開啟並讀取某個文字檔:本例會開啟檔案"Textfile.txt"
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 次。