Access statistics [FSO operation] [asp]

Source: Internet
Author: User

The FileSystemObject object is used to access the file system on the server.

FileSystem and TextStream objects can be used to establish access to the file system and provide a mechanism for sequential file access. FileSystem has no attributes. There are only two methods. The first method is the CreateTextFile method. You can create a new text file on the host and return the TextStream object to provide access to the newly created file. The second method is the OpenTextFile method, which is used to open text files for sequential access and return a TextStream object.

=

CreateTextFile Method

Definition and usage

The CreateTextFile method creates a text file in the current folder and returns a TextStream object that can be used to read or write files.

Syntax:
FileSystemObject.CreateTextFile(filename[,overwrite[,unicode]])FolderObject.CreateTextFile(filename[,overwrite[,unicode]])
Parameters Description
Filename Required. Name of the file to be created.
Overwrite Optional. Indicates whether the Boolean value of an existing file can be overwritten. True indicates that the file can be overwritten, and False indicates that the file cannot be overwritten. The default value is True.
Unicode Optional. Indicates whether the object is a Boolean value created as a Unicode or ASCII file. True indicates that the file is created as a Unicode file, whereas False
Indicates that the file is created as an ASCII file. The default value is False.
Instance for FileSystemObject object
<%
dim fs,tfile
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile("c:\somefile.txt")
tfile.WriteLine("Hello World!")
tfile.close
set tfile=nothing
set fs=nothing
%>

=

OpenTextFile Method

OpenTextFile method to open the specified file and return the TextStream object that can be used to access the file

Syntax:
FileSystemObject.OpenTextFile(fname,mode,create,format)
Parameters Description
Fname Required. Name of the file to be opened.
Mode Optional. How to open a file.

  • 1 = ForReading-open the file to read data. You cannot write data to this file.
  • 2 = ForWriting-open the file for writing data.
  • 8 = ForAppending-open the file and write data to the end of the file.
Create Optional. Set whether to create a new file if the file name does not exist. True indicates that a new file can be created, and False indicates that the new file will not be created. False
Is the default.
Format Optional. File format.

  • 0 = TristateFalse-open the file with ASCII. Default value.
  • -1 = TristateTrue-open a file with Unicode.
  • -2 = TristateUseDefault-open a file in the default system format.

Instance

<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile(Server.MapPath("testread.txt"),8,true)
f.WriteLine("This text will be added to the end of file")
f.Close
set f=Nothing
set fs=Nothing
%>

=

Access statistics

ManageLogStat. asp

<Table class = "tableBorder" width = "55%" border = "0" align = "center" cellpadding = "5" cellspacing = "1"> <form action = "DelcontentStat. asp "method =" post "> <tr> <th width =" 50% "> access statistics </th> <th> cheating parameter </th> </tr> <tr> <td class = "forumRow" align = "center"> <% Set fs = Server. createObject ("Scripting. fileSystemObject ") Set f = fs. openTextFile (Server. mapPath (".. /count/count.txt "), 1) Stat = f. readAllResponse. write (Stat) f. closeSet f = NothingSet fs = Nothing %> </td> <td align = "center" class = "forumRow"> <input type = "text" name = "Stat" maxlength = "20" value = "<% = Stat %>"/> </td> </tr> <td class = "forumRow"> </td> <td class = "forumRow"> <input type = "submit" value = "modify"/> </td> </tr> </form> </table>

DelContentStat. asp

<%dim fs,fset fs=Server.CreateObject("Scripting.FileSystemObject") set f=fs.CreateTextFile(Server.MapPath("../count/count.txt"),true)Stat = request("Stat")f.write(Stat)f.closeset f=nothingset fs=nothingresponse.redirect request.servervariables("http_referer")%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.