Create a low level file with FoxPro
This simple example uses the
FCREATE()
function to create a new file. It then writes some text to the new
file and then closes it.
lnFileHandle =
FCREATE
('fred.txt')
FWRITE
(lnFileHandle, 'Hello Mum')
FCLOSE
(lnFileHandle)
This example has ignored any possible errors in the return values
from the functions. The most important of these is that
FCREATE()
returns a value of -1 as the file handle if it cannot
create the file. In a real application you must check that you
have a valid file handle before you use it in any of the other
low-level functions.
Another factor I've ignored is the location of the new file. I
have just given a simple name for the file so the file will be
created in FoxPro's current folder - not necessarily in the same
folder as the sample program.
By default FCREATE() will create
a file with Read/Write access. You can pass a second parameter
to create a Hidden, Read-Only or System file.
Be careful.
The numeric codes for this function are not the same as the codes for the
FOPEN() function.
Warning
You will have the file locked from the time you open
it to the time that you close it. Remember to release the file by
calling FCLOSE(). The general
command CLOSE ALL will also close
any files you have open for low-level access.
|