Name
FileSystemObject.OpenTextFile Method
Syntax
oFileSysObj.OpenTextFile(FileName[,IOMode[,Create[,Format]]])
oFileSysObjUse: Required
Data Type: FileSystemObject object
A FileSystemObject object.
FileNameUse: Required
Data Type: String
The path and filename of the file to open.
IOModeUse: Optional
Data Type: Long
A constant specifying the purpose for opening the file.
CreateUse: Optional
Data Type: Boolean
A Boolean flag denoting whether the file should be created if it can’t be found in the given path.
FormatUse: Optional
Data Type: Long
A constant specifying ASCII or Unicode format.
Return Value
A TextStream object.
Description
Opens (and optionally first creates) a text file for reading or writing.
Rules at a Glance
File open (
IOMode) values are:
Constant | Value | Description |
| 8 | Opens the file for appending; that is, the current contents of the file are protected and new data written to the file is placed at the end of the file. |
| 1 | Opens the file for reading; |
| 2 | Opens the file for writing; all previous file content is overwritten by new data. |
Tristate (
Format) values are:
Constant | Value | Description |
| -2 | Opens as System default |
| -1 | Opens as Unicode |
| 0 | Opens as ASCII |
The path element of
FileNamecan be relative or absolute.The default
IOModesetting isForReading(1).The default
Formatsetting is ASCII (False).If another process has opened the file, the method fails with a “Permission Denied” error.
Programming ...
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