Partager via


FCREATE( ) Function

Creates and opens a low-level file.

FCREATE(cFileName [, nFileAttribute])

Return Values

Numeric

Parameters

  • cFileName
    Specifies the name of the file to create. You can include a drive designator and path with the file name. If a drive designator or path isn't included, the file is created in the default directory.

    Note   Visual FoxPro does not recognize a path name properly if a disk or directory name contains an exclamation point (!).

  • nFileAttribute
    Specifies the attributes of the file created. The following table lists the file attributes you can specify.

    nFileAttribute File attributes
    0 (Default) Read/write
    1 Read-only
    2 Hidden
    3 Read-only/Hidden
    4 System
    5 Read-only/System
    6 System/Hidden
    7 Read-only/Hidden/System

    Note that a file created with nFileAttribute other than 0 cannot be written to with FPUTS( ) or FWRITE( ) until the file is closed and opened again.

    Use DISPLAY STATUS or LIST STATUS to display or print information about files created and opened with FCREATE( ). DISPLAY STATUS and LIST STATUS give the following information about each file opened or created with a low-level file function:

    • The drive, directory, and file name
    • The file handle number
    • The file pointer position
    • The read/write attributes

Remarks

If a file with the name you specify already exists, it is overwritten without warning.

FCREATE( ) assigns a file handle number to the file, which you can use to identify the file in other Visual FoxPro low-level file functions. FCREATE( ) returns the file handle number when a file is created, or returns –1 if the file cannot be created.

Tip   Assign the file handle number to a memory variable so you can access the file by the variable in other low-level file functions.

You cannot open a communication port with FCREATE( ). Use FOPEN( ) to open a communication port.

Example

IF FILE('errors.txt')  && Does file exist? 
   gnErrFile = FOPEN('errors.txt',12)     && If so, open read/write
ELSE
   gnErrFile = FCREATE('errors.txt')  && If not create it
ENDIF
IF gnErrFile < 0     && Check for error opening file
   WAIT 'Cannot open or create output file' WINDOW NOWAIT
ELSE  && If no error, write to file
   =FWRITE(gnErrFile , 'Error information to be written here')
ENDIF
=FCLOSE(gnErrFile )     && Close file
IF gnErrFile > 0
MODIFY FILE errors.txt NOWAIT  && Open file in edit window
ENDIF  

See Also

CLOSE ALL | FCHSIZE( ) | FCREATE( ) | FEOF( ) | FFLUSH( ) | FGETS( ) | FOPEN( ) | FPUTS( ) | FREAD( ) | FSEEK( ) | FWRITE( )