From WikiChip
mirc/file handling
< mirc
Revision as of 09:51, 19 September 2014 by Ouims (talk | contribs) (/fopen)

File Handling allows you to manipulate files on disk using seperate, simple operations. This allows for efficiency.

To understand how it works, you must be familiar with text file operations such as /write and $read.

Let's take a looke at /write, /write is powerful tool which allows you to write to a file according to severals predefined options.

A simple "/write filename.txt line" involves the following file handling operations:

  • /fopen
  • /fseek
  • /fwrite
  • /fclose

/fopen

/fopen [-nox] <name> <filename>

/fopen opens the filename and use the specified name to reference it.

The command fail by default if the file does not exists, the -n switch create the file if it does not exist, fails if it exists. The -o switch create a new file if it does not exist but overwrite the file if it exists. The -x switch opens the file for exclusive access, others processus cannot access that file

Note: if /fopen fails, it does not halt processing, you must check $ferr to see if any error occured, see below.

After you opened a file with /fopen, you have a pointer of the content of the file, it starts at 0. This pointer is the starting position to read/write from.

/fseek

/fseek -lnwr <name> <position>

/fseek sets the read/write pointer to the specified <position in the file, unless you use a switch:

  • -l - sets the pointer to the beginning of the Nth line, use <position> to specify the Nth line
  • -n - sets the pointer to the beginning of the next line (from the current position of the read/write pointer), this does not take a parameter
  • -w - sets the pointer to the beginning of the line matching the wildcard expression, use <position> to specify the wildcard expression
  • -r - sets the pointer to the beginning of the line matching the regular expression, use <position> to specify the regular expression

If /fseek fails, it sets the pointer to the end of the file.