It creates a specified file name and returns a TextStream object that can be used to read from or write to the file.
Syntax: Set objfile = fso.CreateTextFile(filename[, overwrite[, Unicode]])
fso: (Required) The name of a FileSystemObject object previously instantiated.
filename: (Required) A string expression that identifies the file to create.
overwrite: (Optional) Boolean value that indicates whether you can overwrite an existing file. The value is True if the file.
can be overwritten, False if it can't be overwritten. If omitted, existing files are not overwritten (default False).
unicode: (Optional) Boolean value that indicates whether the file is created as a Unicode or ASCII file. If the value is True, the file is created as a Unicode file. If the value is False, the file is created as an ASCII file. If omitted, an ASCII file is assumed.
'Create a filesystemObject Set fso=createobject("Scripting.FileSystemObject") 'Create a non existing file "qtptest.txt " with overwrite option as True Set qfile1=fso.CreateTextFile("C:qtptest.txt",True,False) Output --> New File "qtptest.txt " is created 'Close the files qfile1.Close 'Release the allocated objects Set qfile1=nothing
'Create a filesystemObject Set fso=createobject("Scripting.FileSystemObject") 'Create a file "qtptest.txt " in C Drive . 'Then run the below statement with overwrite option as False. 'Output --> Error message "Fie already exists" is displayed Set qfile2=fso.CreateTextFile("C:qtpexist.txt",False,False) Set fso=nothing