mIRC Home    About    Download    Register    News    Help

Topic Options
#228857 - 12/01/11 06:37 PM fseek / fwrite
Knoeki Offline
Vogon poet

Registered: 28/01/09
Posts: 116
Loc: Amsterdam, The Netherlands
Okay, this is doing my head in. I can't figure it out anymore.

What I want to do is the following:

1) set pointer to start of file
2) search the file to see if $+($2,*) already exists
3) if so, remove the line
4) set pointer to end of file
5) write $2- to file

I'm not even sure if #1 is needed, but yeah.

I sort of understand how it works, it's just that I can't figure out how to remove a line, and how to set the pointer to the end of the file..

And yes, I realize I could use regular /write, but I'm stubborn and want to use file handlers. :>
_________________________
http://zowb.net

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

Top
#228859 - 12/01/11 09:22 PM Re: fseek / fwrite [Re: Knoeki]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
I don't use file handling often, but I don't know of a file handling method of deleting a line. I mean, you could write every line after the found line up one line in the file, effectively deleting the line, but that's far from efficient. What's wrong with using /write? File handling has its uses and can definitely be better than /write, but that doesn't mean it's always the best solution to a problem.

Code:
alias Example {
  write -dw $+($2,*) temp.txt
  write temp.txt $2-
}


It really can't get much simpler than that.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#228861 - 12/01/11 10:24 PM Re: fseek / fwrite [Re: Riamus2]
Knoeki Offline
Vogon poet

Registered: 28/01/09
Posts: 116
Loc: Amsterdam, The Netherlands
From what I understand, file handling is faster. Consider that there's a really good chance I'll have to process several lines per second.

However, I've found that what I want to do with file handling, isn't going to be feasable. Or rather, it'll end up being way more complicated than needed.

Thanks for the reply anyway, it's much appreciated, but I'm going to consider a different method. (:
_________________________
http://zowb.net

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

Top
#228863 - 12/01/11 10:42 PM Re: fseek / fwrite [Re: Knoeki]
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2876
File handling is only faster if you need to perform more than one operation on the same file.

For example,

/write on its own would be faster than /fopen | /fwrite | /fclose, but if you need to do more than one /write on the same file, you'd be better off using file handling commands or /filter

However you need to consider when to open and close the file handle. If you don't close the file handle when mIRC exits (be it manually or because it crashed or something), there's a chance your file will be corrupted. This is why it's not really safe to keep a file handle open for too long; in case mIRC crashes.

Top