Txt files
Description:
We’ll use a .txt file to store information in sort of list.
Can use to permanently store custom @windows data.
Advantages:
Unlimited storage space (well, you won’t fill your HDD with this).
Has powerful sorting and search options using /filter and other premade $identifiers .
Can be loaded easily into @windows for quicker management.
Has an inbuilt $identifier to retrieve random data.
Disadvantages:
Takes a lot of cpu power to access the file and use it regularly.
Not as organized as .ini files.
Inefficient access to data (only direct access is by line number).
Storage:
The data is stored in a file on the HDD, in a plain text format.
Adding data:
/write file.txt data
Adds data to the end of the .txt file.
Deleting data:
/Write –dlN file.txt
Deletes the Nth line of data in the file.
/Write –dsText file.txt
Deletes the line that starts with “Text” . Works with –w for wild cards, and –r for regex expressions as well.
/remove file.txt
Will permanently remove the file.
Inserting data:
/write –ilN file.txt data
Inserts the line of data in the Nth line.
/write –lN file.txt data
Inserts the line of data to the Nth line, and overwrites it.
Retrieving data:
Set %random $read(file.txt)
Gets a random line of data from the file.
Set %line $read(file.txt,N)
Gets the Nth line in the text file.
Searching for data:
Set %line $read(file.txt,s,Text,N)
Gets the first matching line that starts with “Text”, starting the search from line N.
Set %line $read(file.txt,w,*wild*match*,N)
Gets the first matching line that matches the *wild*match*, starting the search from line N.
Can replace the w with r to get matches with regex expressions.
Set %lineNum $readn
Gets the number of the line last matched by a $read search.
Sorting and filtering:
/filter –fw file.txt @window
This simple format is an example to show that you can use /filter’s powerful options to sort the text file, and change it. Please read more about it in the mirc’s help file, to take advantage of this ability.
Converting to @windows:
/loadbuf @window file.txt
Will load all lines in the text file to the custom @window .
/savebuf @window file.txt
Will save the custom @window’s contents to the text file.
Retrieving size:
Set %lineNum $lines(file.txt)
Will return the number of lines in the file.
Example:
Load the example to the remotes, and right click on a channel.
menu channel {
TXT Store data: {
savebuf $chan mychanneldata.txt
write -il1 mychanneldata.txt $chan($chan).topic
}
TXT Show data: {
if ($isfile(mychanneldata.txt)) {
echo -a Recorded channel topic: $read(mychanneldata.txt,1)
filter -cffg mychanneldata.txt mychanneldata.txt /^\* $/
echo -a Number of channel events recorded: $lines(mychanneldata.txt)
echo -a Here's the last event in the channel: $read(mychanneldata.txt,$lines(mychanneldata.txt))
echo -a Here's the first join event: $read(mychanneldata.txt,w,$+(*,joined,*))
echo -a That appeared in line: $readn
}
}
TXT Remove data :{
if ($isfile(mychanneldata.txt)) remove mychanneldata.txt
}
}