From WikiChip
/fopen Command - mIRC
< mirc‎ | commands
Revision as of 19:23, 15 June 2017 by ChippyBot (talk | contribs) (Bot: de-linking old mIRC menu)

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.

Synopsis

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

Switches

  • -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

  • <handle> - A handle associated with an open file.
  • <filename> - The filename to open.

Example

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

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

Added: 29/08/2003

See also

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