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.

*-- 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.

Access Tips

FoxPro Tips

General Tips

 

Related Items

FoxPro Functions

FoxPro has always had functions like FREAD and FWRITE to read and write files at a low level. They can handle files which defeat the STRTOFILE and FILETOSTR functions.

Read More

Functions for manipulating text in FoxPro

Foxpro commands and functions for text

Read More

Close a low level file in FoxPro

Use FCLOSE() to close a low level file in FoxPro

Read More

Open a low level file in FoxPro

Use FOPEN() to open a low level file in FoxPro

Read More

Read from a low level file in FoxPro

Use FREAD() to read data from a low level file in FoxPro

Read More