Create a low level file


This simple example uses FCREATE() to create a new file. It then writes some text to it and closes the file.

*-- Create a new file ...
lnFileHandle = FCREATE ('fred.txt')
*-- ... write some text into the file ...
FWRITE (lnFileHandle, 'Hello Mum')
*-- ... and close it.
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.


Other low level topics

Low level overview | FOPEN() | FCLOSE() | FREAD() | FWRITE()


Hints & tips

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map