📄 vbs277.htm
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>
<HEAD>
<TITLE>CreateTextFile Method</TITLE>
<META NAME="CATEGORY" CONTENT="Language Reference">
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso8859-1">
<META NAME="PRODUCT" CONTENT="Visual Basic Scripting Edition">
<META NAME="TECHNOLOGY" CONTENT="SCRIPTING">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="CreateTextFile Method">
</HEAD>
<BODY BGCOLOR=FFFFFF LINK=#0033CC>
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END-->
<FONT FACE="Verdana, Arial, Helvetica" SIZE=2>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR VALIGN=TOP><TD WIDTH=360>
<FONT SIZE=1 COLOR=#660033>Microsoft® Visual Basic® Scripting Edition</FONT><BR>
<FONT SIZE=5 COLOR=#660033><B>CreateTextFile Method</B></FONT>
</TD>
<TD ALIGN=RIGHT>
<FONT SIZE=2> <A HREF="vbstoc.htm">Language Reference</A> <BR>
<A HREF="vbs16.htm">Version 2</A> <P></FONT>
</TD></TR>
</TABLE>
<FONT SIZE=2><P>
<A HREF="vbs279.htm">See Also</A>
<A HREF="vbs278.htm">Applies to</A></FONT>
<HR noshade SIZE=1>
<H5>Description</H5>
<BLOCKQUOTE>Creates a specified file name and returns a <b>TextStream</b> object that can be used to read from or write to the file.</BLOCKQUOTE>
<H5>Syntax</H5>
<BLOCKQUOTE><i>object</i>.<b>CreateTextFile(</b><i>filename</i>[<b>,</b> <i>overwrite</i>[<b>,</b> <i>unicode</i>]]<b>)</b><P>
The <b>CreateTextFile</b> method has these parts:<P>
<TABLE WIDTH=87% BORDER=1 CELLPADDING=5 CELLSPACING=0>
<TR VALIGN=TOP BGCOLOR="#DDDDDD">
<TD><FONT SIZE=2><b>Part</b></FONT></TD>
<TD><FONT SIZE=2><b>Description</b></FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>object</i></FONT></TD>
<TD><FONT SIZE=2>Required. Always the name of a <b>FileSystemObject</b> or <b>Folder</b> object.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>filename</i></FONT></TD>
<TD><FONT SIZE=2>Required. <A HREF="vbs0.htm#defStringExpression">String expression</A> that identifies the file to create.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>overwrite</i></FONT></TD>
<TD><FONT SIZE=2>Optional. Boolean value that indicates if an existing file can be overwritten. The value is <b>True</b> if the file can be overwritten; <b>False</b> if it can't be overwritten. If omitted, existing files are not overwritten.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>unicode</i></FONT></TD>
<TD><FONT SIZE=2>Optional. Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is <b>True</b> if the file is created as a Unicode file; <b>False</b> if it's created as an ASCII file. If omitted, an ASCII file is assumed.</FONT></TD></TR>
</TABLE>
</BLOCKQUOTE>
<H5>Remarks</H5>
<BLOCKQUOTE>
The following code illustrates how to use the <b>CreateTextFile</b> method to create and open a text file:
<BLOCKQUOTE><PRE><FONT FACE="Courier New" SIZE=3>Sub CreateAfile
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.<FONT COLOR="#FF0000">CreateTextFile(</FONT>"c:\testfile.txt"<FONT COLOR="#FF0000">,</FONT> True<FONT COLOR="#FF0000">)</FONT>
a.WriteLine("This is a test.")
a.Close
End Sub
</FONT></PRE></BLOCKQUOTE>
If the <i>overwrite</i> argument is <b>False</b>, or is not provided, for a <i>filename</i> that already exists, an error occurs.
</BLOCKQUOTE>
<hr noshade size=1>
<p align=center><em><a href="../../common/colegal.htm">© 1997 by Microsoft Corporation. All rights reserved.</a></em></p>
</FONT></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -