1.AtEndOfStream
This property indicates whether the end of the entire text file has been reached. Its value is "TRUE" or "FALSE"
2.CreateTextFile
Used to create a new text file
Parameters in the 3.OpenTextFile () method
Written by Saucer (Shi):
| The code is as follows |
Copy Code |
| Set f = fso. OpenTextFile ("C:testfile.txt", ForWriting, True) |
The ForWriting value is 2, which means that a writable text file is opened
is 1, which means that a readable text file is opened
Is 8, indicating that you want to append data
True indicates that if this file is not in place, a new
This argument can choose True or false to indicate whether the file is created when it does not exist
Instance 1
Read the file:
| The code is as follows |
Copy Code |
<%
Set Myfileobject=server.createobject ("Scripting.FileSystemObject")
Set Mytextfile=myfileobject.opentextfile ("C:mydirtest.txt")
While not Mytextfile.atendofstream
Response.Write (Mytextfile.readline)
Wend
Mytextfile.close
%> |
Write file:
| The code is as follows |
Copy Code |
<%
Set Myfileobject=server. CreateObject ("Scripting.FileSystemObject")
Set Mytextfile=myfileobject. CreateTextFile ("C:mydirtest.txt")
Mytextfile. WriteLine
Mytextfile.close
%> |
Instance 2
FSO to create the simplest access counter
| code is as follows |
copy code |
|
<%
Set Fs=server.createobject ("Scripting.FileSystemObject")
File = Server.MapPath ("Counter.txt")
Set txtr = fs. OpenTextFile (File,1,true) ' opens a read-only file, if it does not exist, create a new
counter=0 ' to zero the counter
if not txtr.atendofstream Then ' Determine where the end is not reached
line = txtr. ReadLine ' reads a row of data
Else
Line=0 ' Otherwise set the initial value to 0
End If
counter=line+1 ' Count plus 1
Set txtw = Fs.opentextfile (file, 2,true) ' Open write-only files file
Txtw.write counter ' write Count
response. Write ("<center> you are the first <b>" &counter& "</b> Guest! </center> ")
Output Count
%> |
This document can be introduced as include in places where statistics and display counts are required.
| The code is as follows |
Copy Code |
|
<!--#include file= "counter.asp"--> |
However, if it is a static page such as HTML, you can use this simple counter in the form of script scripting.
So counter.asp needs to write that.
| The code is as follows |
Copy Code |
|
<%
Response. Write ("document.write" <center> you are the first <b> "&counter&" </b> Guest! </center> "");
%> |
You can use counters using script scripts in HTML static pages that need to be referenced:
| code is as follows |
copy code |
|
<script Src= "counter.asp" ></SCRIPT> |