FileSystemObject.OpenTextFile Method (VB6) |
Yes
oFileSysObj.OpenTextFile(FileName[, IOMode[, Create[, _
Format]]])
oFileSysObj
Use: Required
Data Type: FileSystemObject object
Any object variable returning a FileSystemObject object.
FileName
Use: Required
Data Type: String
The path and filename of the file to open.
IOMode
Use: Optional
Data Type: IOMode constant
A constant specifying the purpose for opening the file.
Create
Use: Optional
Data Type: Boolean
A Boolean flag denoting if the file should be created if it can't be found in the given path.
Format
Use: Optional
Data Type: Tristate constant
A constant specifying ASCII or Unicode format.
A TextStream object.
Opens (and optionally first creates) a text file for reading or writing.
File open (IOMode) constants are:
Constant | Value | Description |
---|---|---|
ForAppending | 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. |
ForReading | 1 | Opens the file for reading; ForReading files are read-only. |
ForWriting | 2 | Opens the file for writing; all previous file content is overwritten by new data. |
Tristate (Format) constants:
Constant | Value | Description |
---|---|---|
TristateUseDefault | –2 | Open as System default |
TristateTrue | –1 | Open as Unicode |
TristateFalse | 0 | Open as ASCII |
The path element of FileName can be relative or absolute.
The default IOMode setting is ForReading (1).
The default Format setting is ASCII (False).
If another process has opened the file, the method fails with a Permission Denied error.
You can use the GetAbsolutePath and FileExists methods prior to calling the OpenTextFile method to ensure its success.
The value of IOMode can be only that of a single constant. For example, a method call such as the following:
lMode = ForReading Or ForWriting oFileSys.OpenTextStream(strFileName, lMode) ' WRONG
generates runtime error 5, "Invalid procedure call or argument."
If the user has adequate rights, path element of FileName can be a network path or share name. For example:
OpenTextFile "\NTSERV1d$RootTwomyFile.txt"