Createtextfile Method
Create a specified file and returnTextstreamObject, which can be used to read or write files created.
Object.Createtextfile(Filename [, overwrite [, Unicode])
Parameters
Object
Required. The name of the FileSystemObject or folder object.
Filename
Required. String expression, indicating the file to be created.
Overwrite
Optional. Boolean indicates whether existing files can be overwritten. If the file can be overwritten, the value isTrueIf the file cannot be overwritten, the value isFalse. If this value is omitted, the existing file will be overwritten.
Unicode
Optional. Boolean indicates whether to create a file in Unicode or ASCII format. If you create a file in unicode format, the value isTrueIf a file is created in ASCII format, the value isFalse. If this part is omitted, an ASCII file is created.
Description
BelowCodeExamplesCreatetextfileMethod 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. Close
End sub
ForFilenameAn existing file. IfOverwriteThe parameter isFalse, Or if this parameter is not provided, an error occurs.
Source: http://www.yesky.com/imagesnew/software/vbscript/html/vsmthCreateTextFile.htm
Below is a small example written by myself. , Code:
On Error resume next
Dim mu_sresult, mu_sfilepath, mu_sfilename
Mu_sresult = "hello, please call 900fd"
Mu_sfilepath = "textfolder /"
Mu_sfilename = mu_sfilepath & "resultvoice.txt"
Dim FS, TS
Set FS = Createobject ("scripting. FileSystemObject ")
If (FS. fileexists (mu_sfilename) then' checks whether the file exists
Msgbox "the file already exists"
End if
Set Ts = FS. createtextfile (mu_sfilename, true, true) 'If the second parameter is not set, the default value is true (overwrite the original file)
TS. writeline mu_sresult
TS. Close
Set Ts = nothing
Set FS = nothing