From WikiChip
Difference between revisions of "mirc/commands/fopen"
< mirc‎ | commands

(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 [[file handling - mIRC|file handling]]. If an error occurred, processing does not halt. You must check that [[$fopen identifier - mIRC|$fopen]](<handle>).err or [[$ferr identifer - mIRC|$ferr]] is not true.
+
{{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 [-no] <handle> <filename>
+
  /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>''' - a handle associated with an open file
+
* '''<handle>''' - A handle associated with an open file.
* '''<filename>''' - the filename to open
+
* '''<filename>''' - The filename to open.
  
 
== Example ==
 
== Example ==
Line 63: Line 69:
  
 
== Compatibility ==
 
== Compatibility ==
Added: 29/08/2003
+
{{mIRC compatibility|6.1}}
 
 
Added On: mIRC v6.1
 
 
 
<small>Note: Individual switches were not taken into consideration.</small>
 
  
 
== 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]]
* [[$fopen identifier - mIRC|$fopen]]
+
* {{mIRC|$fopen}}
* [[$fread identifier - mIRC|$fread]]
+
* {{mIRC|$fread}}
* [[$fgetc identifier - mIRC|$fgetc]]
+
* {{mIRC|$fgetc}}
* [[$feof identifier - mIRC|$feof]]
+
* {{mIRC|$feof}}
* [[$ferr identifier - mIRC|$ferr]]
+
* {{mIRC|$ferr}}
* [[$file identifier - mIRC|$file]]
+
* {{mIRC|$file}}
* [[/fclose command - mIRC|/fclose]]
+
* {{mIRC|/fclose}}
* [[/flist command - mIRC|/flist]]
+
* {{mIRC|/flist}}
* [[/fseek command - mIRC|/fseek]]
+
* {{mIRC|/fseek}}
* [[/fwrite command - mIRC|/fwrite]]
+
* {{mIRC|/fwrite}}
 +
{{mIRC command list}}
  
[[Category:mIRC commands]]
+
[[Category:mIRC commands|fopen command - mIRC]]

Latest revision as of 02: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.

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]

v · d · e mIRC commands list

A /abook, /action, /add, /ajinvite, /alias, /aline, /ame, /amsg, /anick, /aop, /auser, /auto, /autojoin, /avoice, /away

B /background, /ban, /bcopy, /beep, /bindip, /bread, /break, /breplace, /bset, /btrunc, /bunset, /bwrite

C /channel, /clear, /clearall, /clearial, /cline, /clipboard, /close, /closechats, /closedccs, /closefserves, /closemsg, /cnick, /color, /colour, /comclose, /comlist, /commands, /comopen, /comreg, /continue, /copy, /creq, /ctcp, /ctcpreply, /ctcps

D /dcc, /dccserver, /dde, /ddeserver, /debug, /dec, /describe, /dialog, /did, /didtok, /disable, /disconnect, /dlevel, /dline, /dll, Template:mIRC/donotdisturb, /dns, /dqwindow, /drawcopy, /drawdot, /drawfill, /drawline, /drawpic, /drawrect, /drawreplace, /drawrot, /drawsave, /drawscroll, /drawsize /drawtext

E /ebeeps, /echo, /editbox, /else, /elseif, /emailaddr, /enable, /events, /exit

F /fclose, /filter, /findtext, /finger, /firewall, /flash, /flist, /flood, /flush, /flushini, /fnord, /font, /fopen, /fseek, /fsend, /fserve, /fullname, /fupdate, /fwrite

G /ghide, /gload, /gmove, /gopts, /goto, /gplay, /gpoint, /gqreq, /groups, /gshow, /gsize, /gstop, /gtalk, /gunload, /guser

H /hadd, /halt, /haltdef, /hdec, /hdel, /help, /hfree, /hinc, /hload, /hmake, /hotlink, /hop, /hsave

I /ial, /ialclear, /ialmark, /identd, /if, /ignore, /iline, /inc, /iuser

J /join

L /leave, /linesep, /links, /list, /load, /loadbuf, /localinfo, /log, /logview

M /maxdepth, /mdi, /me, /menubar, /mkdir, /mnick, /mode, /msg

N /noop, /notice, /notify

O /onotice, /omsg

P /pareline, /part, /partall, /pdcc, /perform, /play, /playctrl, /pop, /protect, /proxy, /pvoice

Q /qme, /qmsg, /query, /queryrn, /quit, /quote

R /raw, /registration, /reload, /remini, /remote, /remove, /rename, /renwin, /reseterror, /resetidle, /return, /returnex, /rlevel, /rline, /rmdir, /run, /ruser

S /save, /savebuf, /saveini, /say, /scid, /scon, /server, /set, /setlayer, /showmirc, /signal, /sline, /sockaccept, /sockclose, /socklist, /socklisten, /sockmark, /sockopen, /sockpause, /sockread, /sockrename, /sockudp, /sockwrite, /sound, /speak, /splay, /sreq, /strip, /switchbar

T /timer, /timestamp, /tip, /tips, /titlebar, /tnick, /tokenize, /toolbar, /topic /tray, /treebar

U /ulist, /unload, /unset, /unsetall, /updatenl, /url, /username, /uwho

V /var, /vcadd, /vcmd, /vcrem, /vol

W

X /xyzzy