Skip to content
Don Baechtel edited this page Nov 24, 2018 · 16 revisions

File API

The File API allows access to several different file operations. Opening, Closing, and Reading files, etc.
The files are Read/Written to directories under the directory: C:\Users{username}\AppData\Local\VirtualStore\Program Files (x86)\Alveo.

OpenFileMode Constants
FileOpen
FileClose
FileDelete
FileFlush
FileIsEnding
FileOpenHistory
FileIsLineEnding
FileReadArray
FileReadDouble
FileReadInteger
FileReadNumber
FileReadString
FileSeek
FileSize
FileTell
FileWrite
FileWriteArray
FileWriteDouble
FileWriteInteger
FileWriteString

OpenFileMode Constants

OpenFileMode flags used as mode in the FileOpen function. More than 1 falg can be combined by oring them together.

public enum OpenFileMode
    {
        FILE_BIN = 2,
        FILE_CSV = 4,
        FILE_READ = 8,
        FILE_WRITE = 16
    }

FileOpen

The function opens the file with the specified name and flag

public int FileOpen(string filepath, int mode, char delimiter = ';')

Parameters

  • filepath - Full path to file
  • mode - OpenFileMode flag combination
  • delimiter - Value to be used as a separator in txt or csv-file (';' default)

Returns

  • If a file has been opened successfully, the function returns the file handle, which is then used to access the file data. In case of failure returns INVALID_HANDLE (-1).
  • If the file is already Open or does not exist, then INVALID_HANDLE will be returned.

Example

string path = "myFile.txt";
int filehandle=FileOpen(path, OpenFileMode.FILE_WRITE);
if (filehandle != INVALID_HANDLE) ...

FileClose

Close the file previously opened by FileOpen()

public void FileClose(int handle)

Parameters

  • handle - File descriptor returned by FileOpen()

FileDelete

Deletes the specified file in a local folder of the client terminal

protected void FileDelete(string filepath)

Parameters

  • filepath - Full path to file

FileFlush

Writes to a disk all data remaining in the input/output file buffer

protected void FileFlush(int handle)

Parameters

  • handel - File descriptor returned by FileOpen()

FileIsEnding

Defines the end of a file in the process of reading

protected bool FileIsEnding(int handle)

Parameters

  • handle - File descriptor returned by FileOpen()

Returns

  • True if the file end has been reached in the process of reading or moving of the file pointer

FileOpenHistory

Opens file in the current history directory (terminal_directory\history\server_name) or in its subfolders

protected int FileOpenHistory(string filepath, int mode, char delimiter = ';')

Parameters

  • filepath - File path
  • mode - Open flags combination
  • delimiter - Value to be used as a separator in txt or csv-file (';' default)

Returns

  • If a file has been opened successfully, the function returns the file handle, which is then used to access the file data. In case of failure returns INVALID_HANDLE

FileIsLineEnding

Defines the line end in a text file in the process of reading

protected bool FileIsLineEnding(int handle)

Parameters

  • handle - File descriptor returned by FileOpen()

Returns

  • Returns true if in the process of reading txt or csv-file reached the end of the line (the characters CR-LF)

FileReadArray

Reads from a file of BIN type arrays of any type except string (may be an array of structures, not containing strings, and dynamic arrays)

protected int FileReadArray(int handle, double[] array, int start, int count)

Parameters

  • handle - File descriptor returned by FileOpen()
  • array - An array where the data will be loaded
  • start - Start position to write to the array
  • count - Number of elements to read. By default, reads the entire array (WHOLE_ARRAY default)

Returns

  • Number of elements read or -1 in case of error

FileReadDouble

Reads a double-precision floating point number (double) from the current position of the binary file

protected double FileReadDouble(int handle, int size = (int)ReadDoubleSize.DOUBLE_VALUE)

Parameters

  • handle - File descriptor returned by FileOpen()
  • size - Number of bytes (up to 8 inclusive), that should be read (DOUBLE_VALUE default)

Returns

  • Readed value of double type

FileReadInteger

The function reads int, short or char value from the current position of the file pointer depending on the length specified in bytes

protected int FileReadInteger(int handle, int size = (int)ReadIntegerSize.LONG_VALUE)

Parameters

  • handle - File descriptor returned by FileOpen()
  • size - Number of bytes (up to 4 inclusive), that should be read (LONG_VALUE default)

Returns

  • Readed value of integer type

FileReadNumber

The function reads from the CSV file a string from the current position till a separator (or till the end of a text string) and converts the read string to a value of double type

protected double FileReadNumber(int handle)

Parameters

  • handle - File descriptor returned by FileOpen()

Returns

  • The value of double type

FileReadString

The function reads from a string from the current position of a file pointer in a file

protected string FileReadString(int handle, int length = 0)

Parameters

  • handle - File descriptor returned by FileOpen()
  • length - Number of characters to read

Returns

  • Readed string

FileSeek

The function moves the position of the file pointer by a specified number of bytes relative to the specified position

protected bool FileSeek(int handle, int offset, int origin)

Parameters

  • handle - File descriptor returned by FileOpen()
  • offset - The shift in bytes
  • origin - The starting point for the displacement

Returns

  • Return true in case of success

FileSize

The function returns the file size in bytes

protected int FileSize(int handle)

Parameters

  • handle - File descriptor returned by FileOpen()

Returns

  • returns the file size in bytes

FileTell

The function returns the current position of the file pointer of an open file

protected int FileTell(int handle)

Parameters

  • handle - File descriptor returned by FileOpen()

Returns

  • Current position of the file descriptor in bytes from the beginning of the file

FileWrite

The function is intended for writing of data into a CSV file, delimiter being inserted automatically unless it is equal to 0

protected int FileWrite(int handle, params object[] values)

Parameters

  • handle - File descriptor returned by FileOpen()
  • value - Values to write

Returns

  • Number of bytes written or -1 in case of error

FileWriteArray

The function writes arrays of any type except for string to a BIN file (can be an array of structures not containing strings or dynamic arrays)

protected int FileWriteArray(int handle, object[] array, int start, int count)

Parameters

  • handle - File descriptor returned by FileOpen()
  • array - Array to write
  • start - Initial index in the array
  • count - Number of items to write

Returns

  • Number of elements written or -1 in case of error

FileWriteDouble

The function writes the value of a double parameter to a file, starting from the current position of the file pointer

protected int FileWriteDouble(int handle, double value, int size = (int)ReadDoubleSize.DOUBLE_VALUE)

Parameters

  • handle - File descriptor returned by FileOpen()
  • value - value to write
  • size - Size of element for write (DOUBLE_VALUE default)

Returns

  • If successful the function returns the number of bytes written or -1 in case of error

FileWriteInteger

The function writes the value of the int parameter to a bin-file, starting from the current position of the file pointer

protected int FileWriteInteger(int handle, int value, int size = (int)ReadIntegerSize.LONG_VALUE)

Parameters

  • handle - File descriptor returned by FileOpen()
  • value - value to write
  • sie - Size of element for write (LONG_VALUE default)

Returns

  • If successful the function returns the number of bytes written or -1 in case of error

FileWriteString

The function writes the value of a string-type parameter into a BIN, CSV or TXT file starting from the current position of the file pointer

protected int FileWriteString(int handle, string value, int size)

Parameters

  • handle - File descriptor returned by FileOpen()
  • value - value to write
  • size - Size of element for write

Returns

  • If successful the function returns the number of bytes written or -1 in case of error