ClassesClasses | | Operators

open_fileT_open_fileOpenFileOpenFile (Operator)

Name

open_fileT_open_fileOpenFileOpenFile — Open a file in ASCII or a binary format.

Signature

open_file( : : FileName, FileType : FileHandle)

Herror T_open_file(const Htuple FileName, const Htuple FileType, Htuple* FileHandle)

void OpenFile(const HTuple& FileName, const HTuple& FileType, HTuple* FileHandle)

void HFile::HFile(const HString& FileName, const HString& FileType)

void HFile::HFile(const char* FileName, const char* FileType)

void HFile::OpenFile(const HString& FileName, const HString& FileType)

void HFile::OpenFile(const char* FileName, const char* FileType)

static void HOperatorSet.OpenFile(HTuple fileName, HTuple fileType, out HTuple fileHandle)

public HFile(string fileName, string fileType)

void HFile.OpenFile(string fileName, string fileType)

Description

open_fileopen_fileOpenFileOpenFileOpenFile opens a file in ASCII format or in binary format. The name of the file is defined by the parameter FileNameFileNameFileNameFileNamefileName. The operator returns the FileHandleFileHandleFileHandleFileHandlefileHandle. The parameter FileTypeFileTypeFileTypeFileTypefileType determines the type of the file.

The following settings for FileTypeFileTypeFileTypeFileTypefileType are supported:

'input'"input""input""input""input":

An already existing input file is opened for reading in ASCII format.

'output'"output""output""output""output":

A new output file is opened for writing in ASCII format.

'append'"append""append""append""append":

An already existing output file is opened at the end of the file for writing in ASCII format.

'input_binary'"input_binary""input_binary""input_binary""input_binary":

An already existing input file is opened for reading in binary format.

'output_binary'"output_binary""output_binary""output_binary""output_binary":

A new output file is opened for writing in binary format.

'append_binary'"append_binary""append_binary""append_binary""append_binary":

An already existing output file is opened at the end of the file for writing in binary format.

For terminal input and output, the file names 'standard'"standard""standard""standard""standard" ('input'"input""input""input""input" and 'output'"output""output""output""output") and 'error'"error""error""error""error" (only 'output'"output""output""output""output") are reserved.

Execution Information

This operator returns a handle. Note that the state of an instance of this handle type may be changed by specific operators even though the handle is used as an input parameter by those operators.

Parameters

FileNameFileNameFileNameFileNamefileName (input_control)  filename HTupleHTupleHtuple (string) (string) (HString) (char*)

Name of file to be opened.

Default value: 'standard' "standard" "standard" "standard" "standard"

Suggested values: 'standard'"standard""standard""standard""standard", 'error'"error""error""error""error", '/tmp/dat.dat'"/tmp/dat.dat""/tmp/dat.dat""/tmp/dat.dat""/tmp/dat.dat"

FileTypeFileTypeFileTypeFileTypefileType (input_control)  string HTupleHTupleHtuple (string) (string) (HString) (char*)

Type of file.

Default value: 'output' "output" "output" "output" "output"

List of values: 'append'"append""append""append""append", 'append_binary'"append_binary""append_binary""append_binary""append_binary", 'input'"input""input""input""input", 'input_binary'"input_binary""input_binary""input_binary""input_binary", 'output'"output""output""output""output", 'output_binary'"output_binary""output_binary""output_binary""output_binary"

FileHandleFileHandleFileHandleFileHandlefileHandle (output_control)  file HFile, HTupleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

File handle.

Example (HDevelop)

* Creating an output file with the name '/tmp/log.txt' and writing
* of a string:
   open_file('/tmp/log.txt','output',FileHandle)
   fwrite_string(FileHandle,'these are the first and last lines')
   fnew_line(FileHandle)
   close_file(FileHandle)
   

Example (C)

/* Creating an output file with the name '/tmp/log.txt' and writing */
/* of a string:                                                    */
   open_file("/tmp/log.txt","output",&FileHandle) ;
   fwrite_string(FileHandle,"these are the first and last lines") ;
   fnew_line(FileHandle) ;
   close_file(FileHandle);
   

Example (HDevelop)

* Creating an output file with the name '/tmp/log.txt' and writing
* of a string:
   open_file('/tmp/log.txt','output',FileHandle)
   fwrite_string(FileHandle,'these are the first and last lines')
   fnew_line(FileHandle)
   close_file(FileHandle)
   

Example (HDevelop)

* Creating an output file with the name '/tmp/log.txt' and writing
* of a string:
   open_file('/tmp/log.txt','output',FileHandle)
   fwrite_string(FileHandle,'these are the first and last lines')
   fnew_line(FileHandle)
   close_file(FileHandle)
   

Example (HDevelop)

* Creating an output file with the name '/tmp/log.txt' and writing
* of a string:
   open_file('/tmp/log.txt','output',FileHandle)
   fwrite_string(FileHandle,'these are the first and last lines')
   fnew_line(FileHandle)
   close_file(FileHandle)
   

Result

If the parameters are valid, the operator open_fileopen_fileOpenFileOpenFileOpenFile returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

Possible Successors

fwrite_stringfwrite_stringFwriteStringFwriteStringFwriteString, fread_charfread_charFreadCharFreadCharFreadChar, fread_stringfread_stringFreadStringFreadStringFreadString, fread_linefread_lineFreadLineFreadLineFreadLine, fread_serialized_itemfread_serialized_itemFreadSerializedItemFreadSerializedItemFreadSerializedItem, fwrite_serialized_itemfwrite_serialized_itemFwriteSerializedItemFwriteSerializedItemFwriteSerializedItem, close_fileclose_fileCloseFileCloseFileCloseFile

See also

close_fileclose_fileCloseFileCloseFileCloseFile, fwrite_stringfwrite_stringFwriteStringFwriteStringFwriteString, fread_charfread_charFreadCharFreadCharFreadChar, fread_stringfread_stringFreadStringFreadStringFreadString, fread_linefread_lineFreadLineFreadLineFreadLine

Module

Foundation


ClassesClasses | | Operators