Object. opentextfile (filename [, iomode [, create [, format])
Parameters
Object: required. The name of the FileSystemObject object.
Filename: required. String expression, indicating the name of the file to be opened.
Iomode: Optional. The input/output mode is one of the following three constants: forreading, forwriting, or forappending.
Create: Optional. Boolean value indicates whether a new file can be created if the specified filename does not exist. True is allowed when a new file is created. Otherwise, false is allowed. The default value is false.
Format: Optional. Indicates the format in which the file is opened. If this parameter is ignored, the file is opened in ASCII format.
Set
The iomode parameter can be set as follows:
Constant Value description
Forreading 1 open the file in read-only mode. You cannot write this file.
Forwriting 2 opens the file in write-only mode. You cannot read this file.
Forappending 8 open the file and write it at the end of the file.
The format parameter can be set as follows:
Constant Value description
Tristateusedefault-2 open a file in the default format.
Tristatetrue-1 open a file in unicode format.
Tristatefalse 0 open the file in ASCII format.
Description
Below Code The following example shows how to use opentextfile to open a file:
Copy code The Code is as follows: Sub opentextfiletest
Const forreading = 1, forwriting = 2, forappending = 8
Dim FSO, F
Set FSO = Createobject ("scripting. FileSystemObject ")
Set F = FSO. opentextfile ("C: \ testfile.txt", forwriting, true)
F. Write "hi, hello! "
F. Close
End sub
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.