mIRC Home    About    Download    Register    News    Help

Print Thread
/fopen additional option #225703 08/09/10 09:48 AM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Quote:
File Handling Commands

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

Opens the specified file and assigns a name to it for later reference. The open fails if the file does not exist. The -n switch creates the file if it does not already exist, fails if the file does exist. The -o switch creates a new file, overwrites if it exists.


It would be lovely, if there was also an option that would create the file if it doesn't exist, and open it if it already exists, in case you just want to append to files.


Learning something new every day.
Re: /fopen additional option [Re: Thels] #225763 09/09/10 04:56 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Makes sense to me, and, imo, using a (for append) is an obvious choice. Of course, the first problem I see, is if you get someone specifying multiple options. Eg: /fopen -ao
Which should be used? or should the order set precedence?

Re: /fopen additional option [Re: Thels] #225766 09/09/10 07:54 AM
Joined: Apr 2010
Posts: 966
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 966
You could just rewrite /fopen, here is an example:

Code:
Opens the specified file and assigns a name to it for later reference
-n switch creates the file if it does not already exist, fails if the file does exist
-o switch creates a new file, overwriting it if it exists
-a switch opens a file if it exists, creates it if it doesn't

alias fopen {

  ;set up /fopen command to use mIRC's internal command
  ;also check to see if fopen has been called with a preceeding "." to
  ;not show it's results
  ;%fopen looks something like: !.fopen  
  var %fopen = $+(!,$iif(!$show,.),fopen)

  ;check to see if any switches have been specified, if so make sure they are valid.  
  if (-* iswm $1 && !$regex($1,/^(?:n|o|a)$/i)) {
    ;handle the syntax error how u feel
  }
  
  ;if the switches are valid, and the switch is -a
  elseif ($1 == -a) {
  
    ;check to see if the file exists, and if so, open it with /fopen
    if ($isfile($3-)) {
      %fopen $2-
    }
    
    ;if the file doesn't exist, open it with "/fopen -n" to create it.
    else {
      %fopen -n $2-
    }
  }
  
  ;if /fopen was called without any of the improvements we are trying to make, use the sent command as is.
  else {
    %fopen $1- 
  }
}

I haven't tested it or anything but the concept is pretty easy to follow


I am SReject
My Stuff
Re: /fopen additional option [Re: FroggieDaFrog] #225767 09/09/10 08:25 AM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
" var %fopen = $+(!,$iif(!$show,.),fopen)"

This line is unnecessary as mIRC automatically prefixes all commands called within an alias with a "." if the alias itself was called with a "."

Try this:

Code:
alias test echo -q hello


/test echoes "hello"

/.test does nothing.

Quite a handy feature smile

Re: /fopen additional option [Re: RusselB] #225769 09/09/10 08:50 AM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Originally Posted By: RusselB
Makes sense to me, and, imo, using a (for append) is an obvious choice. Of course, the first problem I see, is if you get someone specifying multiple options. Eg: /fopen -ao
Which should be used? or should the order set precedence?


Afaik, when conflicting switches are given, one specific switch takes priority, regardless of the order of switches.

Wouldn't -n and -o already conflict?

And yes, I know it's fairly easy to script. I just found it odd that with the various switches, there's no "append" switch, while that is the one that feels the most natural to me.


Learning something new every day.
Re: /fopen additional option [Re: Thels] #225778 09/09/10 10:04 AM
Joined: Jan 2009
Posts: 116
Knoeki Offline
Vogon poet
Offline
Vogon poet
Joined: Jan 2009
Posts: 116
I second this motion. Right now I need to check if a file already exists, create the file if it doesn't, then open it.


http://zowb.net

/server -m irc.p2p-network.net -j #zomgwtfbbq
(ssl on port 6697 and 7000)
Re: /fopen additional option [Re: Knoeki] #225780 09/09/10 10:37 AM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Originally Posted By: Knoeki
I second this motion. Right now I need to check if a file already exists, create the file if it doesn't, then open it.


Create it separately?

I use -n if it doesn't exist, and no switches if it does.

Still, it's something lile:

Code:
fopen $iif(!$exists(%filename), -n) file %filename


Where this would be a lot nicer:

Code:
fopen -a file %filename


Learning something new every day.
Re: /fopen additional option [Re: Thels] #225786 09/09/10 11:39 AM
Joined: Jan 2009
Posts: 116
Knoeki Offline
Vogon poet
Offline
Vogon poet
Joined: Jan 2009
Posts: 116
Originally Posted By: Thels
Originally Posted By: Knoeki
I second this motion. Right now I need to check if a file already exists, create the file if it doesn't, then open it.


Create it separately?

I use -n if it doesn't exist, and no switches if it does.


That's pretty much what I'm doing. Sorry if it wasn't clear from what I posted ;_)


http://zowb.net

/server -m irc.p2p-network.net -j #zomgwtfbbq
(ssl on port 6697 and 7000)