Click or drag to resize

FChSize Function

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

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.5
Syntax
 FUNCTION FChSize(
	ptrHandle AS IntPtr,
	dwOffset AS DWORD
) AS LOGIC

Parameters

ptrHandle
Type: IntPtr
The handle of the open file whose size you want to change.
dwOffset
Type: UInt32
The new length to which the file should be set.

Return Value

Type: Boolean
The new length of the file if successful; otherwise, F_ERROR.  FError() can be used to determine the specific error.
Remarks
FChSize() truncates or extends a file to a specified length.
The file should be open for writing and its handle must be available.
If the file size is increased, null characters (Chr(0)) are appended.
Remarks
Tip Tip
The low level File IO functions in the X# runtime are using .Net filestreams in the background.
That means that the file handles returned by FOpen() and FCreate() are not 'normal' file handles, but unique identifiers that are used to find the underlying stream object in a collection of streams in the runtime.
That also means that you can't use file handles for functions such as FRead() and FWrite() that were not created in the X# runtime.
If you want to access the underlying FileStream, then you should call the function FGetStream()
Examples
This example uses FChSize() in conjunction with FOpen2():
X#
1LOCAL hFile
2hFile := FOpen2("docs.txt", F0_READWRITE)
3IF hFile != F_ERROR
4    IF FChSize(hFile, 100) != F_ERROR
5        ? "Size successfully changed to 100"
6    ELSE
7        ? DOSErrString(FError())
8    ENDIF
9ENDIF
See Also