(Created page with "The '''/fopen command''' opens <filename> and assigns it a handle. The file is opened for both writing and reading: see file handling. If an error occ...") |
m (correct linking for another identifier) |
||
(16 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
− | The '''/fopen command''' opens <filename> and assigns it a handle. The file is opened for both writing and reading: see | + | {{mirc title|/fopen Command}} |
+ | The '''/fopen command''' opens <filename> and assigns it a handle. The file is opened for both writing and reading: see {{mIRC|file handling}}. If an error occurred, processing does not halt. You must check that {{mIRC|$fopen}}(<handle>).err or {{mIRC|$ferr}} is not true. | ||
+ | |||
+ | '''Note''': mIRC keeps the handle even after a fail, you must always /fclose the handle you /fopen yourself. | ||
+ | |||
+ | If -x is not used, the file that is opened is also in shared read/write, meaning that an external application (a second mIRC) can also open the file at the same time, read and write to it, affecting the content of the file you're using. | ||
== Synopsis == | == Synopsis == | ||
− | /fopen [- | + | /fopen [-nox] <handle> <filename> |
== Switches == | == Switches == | ||
* '''-n''' - Create a new file, fails if already exists | * '''-n''' - Create a new file, fails if already exists | ||
* '''-o''' - Creates a new file, overriding an old one if exists | * '''-o''' - Creates a new file, overriding an old one if exists | ||
+ | * '''-x''' - Opens the file in exclusive mode (will fail to open if already in use) | ||
== Parameters == | == Parameters == | ||
− | * '''<handle>''' - | + | * '''<handle>''' - A handle associated with an open file. |
− | * '''<filename>''' - | + | * '''<filename>''' - The filename to open. |
== Example == | == Example == | ||
Line 63: | Line 69: | ||
== Compatibility == | == Compatibility == | ||
− | + | {{mIRC compatibility|6.1}} | |
− | |||
− | |||
− | |||
− | |||
== See also == | == See also == | ||
* [[List of commands - mIRC|List of commands]] | * [[List of commands - mIRC|List of commands]] | ||
* [[List of identifiers - mIRC|List of identifiers]] | * [[List of identifiers - mIRC|List of identifiers]] | ||
− | * | + | * {{mIRC|$fopen}} |
− | * | + | * {{mIRC|$fread}} |
− | * | + | * {{mIRC|$fgetc}} |
− | * | + | * {{mIRC|$feof}} |
− | * | + | * {{mIRC|$ferr}} |
− | * | + | * {{mIRC|$file}} |
− | * | + | * {{mIRC|/fclose}} |
− | * | + | * {{mIRC|/flist}} |
− | * | + | * {{mIRC|/fseek}} |
− | * | + | * {{mIRC|/fwrite}} |
+ | {{mIRC command list}} | ||
− | [[Category:mIRC commands]] | + | [[Category:mIRC commands|fopen command - mIRC]] |
Latest revision as of 01:40, 19 January 2024
The /fopen command opens <filename> and assigns it a handle. The file is opened for both writing and reading: see file handling. If an error occurred, processing does not halt. You must check that $fopen(<handle>).err or $ferr is not true.
Note: mIRC keeps the handle even after a fail, you must always /fclose the handle you /fopen yourself.
If -x is not used, the file that is opened is also in shared read/write, meaning that an external application (a second mIRC) can also open the file at the same time, read and write to it, affecting the content of the file you're using.
Contents
Synopsis[edit]
/fopen [-nox] <handle> <filename>
Switches[edit]
- -n - Create a new file, fails if already exists
- -o - Creates a new file, overriding an old one if exists
- -x - Opens the file in exclusive mode (will fail to open if already in use)
Parameters[edit]
- <handle> - A handle associated with an open file.
- <filename> - The filename to open.
Example[edit]
A simple example that prints one line to a new file:
; simple fopen example alias fopen_example { .fopen -n h hello.txt ;error check if ($ferr) { echo -sce info * /fopen_example: example.txt already exists! halt } ;print text .fwrite h Hello There ;close the handle .fclose h ;open file in default editor run hello.txt }
A script that prints all the permutations of there-characters to a file.
; print permutations [aaa]-[zzz] alias perm_example { .fopen -n h example.txt ;error check if ($ferr) { echo -sce info * /fopen_example: example.txt already exists! halt } ;print all the permutations to the file var %x = 97 while (%x < 123) { var %y = 97 while (%y < 123) { var %z = 97 while (%z < 123) { .fwrite -n h $+($chr(%x), $chr(%y), $chr(%z)) inc %z } inc %y } inc %x } ;close the handle .fclose h }
Broken Compatibility[edit]
in mIRC 7.22 /fopen left the handle open even after it failed. The compatibility change stated above was changed back to the old behavior in mIRC 7.24.
Compatibility[edit]
Added: mIRC v6.1
Added on: 29 Aug 2003
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.
See also[edit]
- List of commands
- List of identifiers
- $fopen
- $fread
- $fgetc
- $feof
- $ferr
- $file
- /fclose
- /flist
- /fseek
- /fwrite