Click or drag to resize

FCreate Function (String)

X#
Create a file or open and truncate an existing file.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.19
Syntax
 FUNCTION FCreate(
	cFileName AS STRING
) AS IntPtr
Request Example View Source

Parameters

cFileName
Type: String
The name of the file to create, including an optional drive, directory, and extension. SetDefault() and SetPath() settings are ignored; the Windows default is used unless you specify a drive and directory as part of the file name. No extension is assumed.
If the file already exists, its length is truncated to 0 without warning.
This function sets NetErr() in case of a concurrency control conflict.

Return Value

Type: IntPtr
The DOS file handle number of the new file.
If an error occurs, FCreate() returns F_ERROR. FError() can be used to determine the specific error.
Remarks
FCreate() is a low-level file function that either creates a new file or opens an existing file and truncates it to 0 length.
If cFileName does not exist, it is created and opened for writing.
If it does exist and can be opened for writing, it is truncated to 0 length. When FCreate() successfully creates a new file, the file is left open in compatibility sharing mode and read/write access mode.
The file attribute specified by nAttribute is applied to the new file when it is closed, allowing you to write to a newly created read-only file.
For a list of access modes, see FOpen(). Since a file handle is required in order to identify an open file to other file functions, always assign the return value from FCreate() to a variable for later use.
Examples
This example creates a file called TESTFILE and opens it for reading and writing:
X#
1IF (ptrHandle := FCreate("testfile")) = F_ERROR
2    ? DOSErrString(FError())
3ELSE
4    FWrite(ptrHandle, "Hello there")
5    FClose(ptrHandle)
6ENDIF
See Also