Phantom Documentation

[Help Home] [Phantom Home]
OpenFile

file OpenFile(string,string)

Return Type: file
Parameters: string Path, string Mode

Description:
OpenFile opens a text file, indicated by Path for reading, writing, or appending. Files must be opened using this function with the correct flag prior to performing other file operations. Future file operations are performed using the hFile parameter returned by this function. The different modes, set by the Mode parameter are:


w - The file is open for write access.
r - The file is open for read access.
a - The file is open for append access.


ReadFile requires the ‘r’ mode, and WriteFile requires the ‘w’ or ‘a’ modes. All files opened using OpenFile must be closed by CloseFile after file operations are complete. Note that the Path can either be an absolute path or a relative path.


Example Code
file hFile;
string sName = "test.txt";
string sVar;
bool bSuccess = true;


# Open the File
hFile = OpenFile(sName, "w");



# Write some messages to the file
WriteFile(hFile, "Four score and seven years ago...");
WriteFile(hFile, "Our forefathers...");



# Close the file
CloseFile(hFile);



# Re-open the file for writing
hFile = OpenFile(sName, "r");



# Read and display the whole file
while(bSuccess == true)
{
bSuccess = ReadFile(hFile, sVar);
  disp(sVar);
}

# Close the file
CloseFile(hFile);



The output (int test.txt) from the above example is:


test.txt
Four score and seven years ago...
Our forefathers...
 

Copyright 2000-2011 Phantom Automated Solutions