Valid on NetWare, Symbian OS, UNIX, Windows, and Windows CE
The OpenFile function opens a file for reading or writing.
This file content function has the format:
OpenFile(filename as String, access as Integer, mode as Integer) as Integer
OpenFile(filename as String, access as Integer) as Integer
Specifies the name of the file to open.
Specifies how to open the file. The access parameter can be any of the following predefined constants:
(value 0) Opened for reading.
(value 1) Created for writing. This overwrites the file if it exists.
(value 2) Opened for writing at end of file. This creates a file if it does not exist.
(value 3) Opened for reading and writing.
Indicates an optional parameter to specify binary mode. The mode parameter can be one of the following predefined constants:
Value 0; text mode
Value 1; binary mode
If the mode parameter is omitted, text mode is assumed.
If the function succeeds, the return value is a non-negative integer; that is, the file handle. If the function fails, it returns -1.
Example: OpenFile function
This example creates a backup of the CONFIG.SYS file.
Dim fIn, fOut as integer ' Declare file handles
Dim OneLine as string ' String to hold one line
' First open the Input file...
fIn=OpenFile("C:\CONFIG.SYS",O_READ)
if fIn<0 then
MessageBox("Unable to open input file","Error")
Goto End
End if
' ...Then create the output file...
fOut=CreateFile("C:\CONFIG.BAK")
if fOut<0 then
MessageBox("Unable to create output file","Error")
Goto End
End if
' ...Copy lines until none left...
while Not(Eof(fIn))
if ReadFile(fIn,OneLine) then WriteFile(fOut,OneLine)
wend
' ...Close Files, and signal success.
CloseFile(fIn)
CloseFile(fOut)
MessageBox("A backup of the CONFIG.SYS file was created","MyScript")
end:
|
Copyright © 2013 CA.
All rights reserved.
|
|