ASP (VBS) FSO OpenTextFile method parameter Description _fso topic

Source: Internet
Author: User
Tags constant

OpenTextFile is a method in ASP language
Opens the specified file and returns a TextStream object that can be read, written, or appended to the file by this object.
Object. OpenTextFile (filename[, iomode[, create[, format]])

1. Method Editor opens the specified file and returns a TextStream object that can be read, written, or appended to the file by this object.
object. OpenTextFile (filename[, iomode[, create[, format]])
2. Parameter Edit Object

Required option. Object should be the name of the FileSystemObject.
FileName
Required option. A string expression that indicates the file you want to open.
IOMode
Options available. Can be one of three constants: ForReading, ForWriting, or forappending.
Create
Options available. Boolean value that indicates whether to create a new file when the specified filename does not exist. True If a new file is created, False if it is not created. If omitted, the new file is not created.
Format
Options available. Use one of the three-state values to indicate the format of the open file. If omitted, the file is opened in ASCII format.

3. Setting the edit IOMode parameter can be any of the following settings:

Constant numerical description

ForReading 1 Opens the file as read-only. Can't write this file.
ForWriting 2 Open File as Write
ForAppending 8 Opens the file and begins writing at the end of the file.

The format parameter can be any of the following settings:
Value Description

TristateTrue opens the file in Unicode format.
Tristatefalse opens the file in ASCII format.
Tristateusedefault to open the file using the system default value.

4. Description edit the following code shows how to open a file using the OpenTextFile method and append text:
var FS, A, ForAppending;
ForAppending = 8;
FS = new ActiveXObject ("Scripting.FileSystemObject");
Can be one of three constants: ForReading, ForWriting, or ForAppending
1, 2, 8, respectively.
A = fs. OpenTextFile ("C:\\testfile.txt", 2, false);
...
A.close ();

Use cases in the VBS script

Opens the specified file and returns a TextStream object that can be read, written to, or appended to the file.
Object. OpenTextFile (Filename[,iomode[,create[,format]])
Parameters
Object
Required option. Should be the name of the FileSystemObject object.
FileName
Required option. A string expression that indicates the name of the file to open.
IOMode
Options available. The input/output mode is one of the following three constants: Forreading,forwriting, or ForAppending.
Create
Options available. Boolean value that indicates whether a new file can be created when the specified filename does not exist. True when new files are allowed to be created, otherwise false. The default value is False.
Format
Options available. One of three tristate values that indicates in what format the file is opened. If this argument is omitted, the file is opened in ASCII format.

The IOMode parameter can be one of the following settings:

Constant Value Describe
ForReading 1 Open the file in read-only mode. This file cannot be written to.
ForWriting 2 Opens the file as a write-only method. This file cannot be read.
ForAppending 8 Open the file and write at the end of the file.


The format parameter can be one of the following settings:

Constant Value Describe
Tristateusedefault -2 Open the file in the system default format.
TristateTrue -1 Opens the file in Unicode format.
Tristatefalse 0 Opens the file in ASCII format.

Use examples:

Sub opentextfiletest
Const ForReading =1, ForWriting =2, ForAppending =8
Dim fso, F
Set fso =createobject ("Sc Ripting. FileSystemObject ")
Set F =fso. OpenTextFile ("C:\testfile.txt", forwriting,true)
f.write "Hi, Hello!" "
F.close end
Sub called
opentextfiletest

A function written by the cloud-dwelling community

Dim FSO
Set fso = CreateObject ("Scripting.FileSystemObject")
set FN2=FSO. GetFile ("E:\webroot\jb51\index2.htm")
flsize2=fn2.size
fldate2=fn2.datelastmodified
set FN=FSO. GetFile ("E:\webroot\jb51\index.htm")
flsize1=fn.size
fldate1=fn.datelastmodified
If fso. FileExists ("E:\webroot\jb51\index2.htm") and flsize2>50000 and fldate2>fldate1 Then
' Determine the size of the file, If the HTML file regeneration needs to be judged whether it has been updated and the file cannot be less than 50K
fso.getfile ("E:\webroot\jb51\index2.htm"). Copy ("E:\webroot\jb51\index.htm ")
if Err.number=0 then WriteHistory" Success "&now () &" ... "," Log.txt "End
if"
log write function
Sub writehistory (hischars, path)
 Const ForReading = 1, ForAppending = 8
 Dim fso, f
 Set fso = CreateObject (" Scripting.FileSystemObject ")
 Set f = fso. OpenTextFile (Path, ForAppending, True)
 f.writeline hischars 
 f.close End
Sub

Related Article

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.