VBS Tutorial: Method-createtextfile Method _vbs

Source: Internet
Author: User

CreateTextFile method

Creates a specified file and returns a TextStream object that can be used to read or write the created file.

object.CreateTextFile(filename[, overwrite[, unicode]])

Parameters

Object

Required option. Should be the name of the FileSystemObject or Folder object.

FileName

Required option. A string expression that indicates the file to create.

Overwrite

Options available. A Boolean value that indicates whether an existing file can be overwritten. TrueIf the file can be overwritten, or False If the file cannot be overwritten. If this value is omitted, the existing file cannot be overwritten.

Unicode

Options available. A Boolean value that indicates whether the file is created in Unicode or ASCII file format. TrueIf the file is created in a Unicode file format, FalseIf the file is created in an ASCII file format. If this section is omitted, the ASCII file is assumed to be created.

Description

The following code illustrates how to use the CreateTextFile method to create and open a text file:

Sub CreateAfile  Dim fso, MyFile  Set fso = CreateObject("Scripting.FileSystemObject")  Set MyFile = fso.CreateTextFile("c:\testfile.txt", True) MyFile.WriteLine("This is a test.")  MyFile.CloseEnd Sub

For files where filename already exists, an error occurs if the overwrite argument is Falseor if this parameter is not supplied.

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.