VBS Tutorial: Method-opentextfile Method _vbs

Source: Internet
Author: User

OpenTextFile method

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. TrueWhen 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.

Set up

The iomode parameter can be one of the following settings:

Constants value Description
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 〈p〉 format parameter can be one of the following settings:

Constants value Description
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.

Description

The following code illustrates how to open a write file using the OpenTextFile method:

  Sub opentextfiletest Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim fso, f Set fso = Createobjec T ("Scripting.FileSystemObject") Set f =   FSO. OpenTextFile ( "C:\testfile.txt" ,  for Writing,  True  )  F.write "    " Hi, Hello!    f.close  

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.