Condividi tramite


FCHSIZE( ) Function

Changes the size of a file opened with a low-level file function.

FCHSIZE(nFileHandle, nNewFileSize)

Return Values

Numeric

Parameters

  • nFileHandle
    Specifies the file handle of the file whose size you wish to change. The file handle is returned by FOPEN( ) when you open the file or by FCREATE( ) when you create the file. If a file is opened with FOPEN( ), it must be opened with write or read/write privileges to be able to change its size.
  • nNewFileSize
    Specifies the new file size in bytes. If nNewFileSize is less than the original file size, the file is truncated. If nNewFileSize is greater than the original file size, the file size is increased.

Remarks

Use FCHSIZE( ) to increase the file's size or truncate the file after a specified byte.

When a file's size is increased, Microsoft Visual FoxPro allocates sectors for the file on the drive where the file is opened. Since FCHSIZE( ) does not initialize the new file space, the space can contain previous data. Be sure to manage the new file space.

The final size of the file in bytes is returned. Visual FoxPro returns –1 if FCHSIZE( ) is unable to change the file size if, for example, an invalid file handle is specified because of insufficient disk space, or if the file is read-only.

Tip   This function can be used to truncate a file to length 0.

See Also

FCLOSE( ) | FCREATE( ) | FEOF( ) | FFLUSH( ) | FGETS( ) | FOPEN( ) | FPUTS( ) | FREAD( ) | FSEEK( ) | FWRITE( )