Name
Folder.CreateTextFile Method
Syntax
oFolderObj.CreateTextFileFileName[,Overwrite[,Unicode]])
oFolderObjUse: Required
Data Type: Folder object
A Folder object.
FileNameUse: Required
Data Type: String
Any valid filename and optional path.
OverwriteUse: Optional
Data Type: Boolean
Flag to indicate whether an existing file of the same name should be overwritten.
UnicodeUse: Optional
Data Type: Boolean
Flag to indicate whether file is to be written in Unicode or ASCII.
Return Value
A TextStream object.
Description
Creates a new file at the specified location and returns a TextStream object for that file.
Rules at a Glance
Filenamecan be a relative or absolute path. Wildcard characters are not allowed inFileName.If no path is specified in
Filename, the script’s current drive and directory are used. If no drive is specified inFilename, the script’s current drive is used.The default value for
OverwriteisFalse.If
Unicodeis set toTrue, a Unicode file is created; otherwise it’s created as an ASCII text file.The default value for
UnicodeisFalse.
Programming Tips and Gotchas
If the path specified in
Filenamedoes not exist, the method fails. To prevent this error, you can use the FileSystemObject object’s FolderExists method to be sure that the path is valid.The newly created text file is automatically opened only for writing. If you subsequently wish to read from the file, you must first close it and reopen it in read mode.
If the file referred to in
Filenamealready exists as a read-only file, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access