mScriptBox Tutorial
Introduction to the Filter Command
Written by Sigh_
Published with permission.

Table Of Contents

  1. Introduction
  2. The /filter command in detail
  3. Some Examples
  4. The Switches
  5. Switch w
  6. Switch f
  7. Switch c
  8. Some Examples
  9. Switch s
  10. Switch d
  11. Switch x
  12. Switch b
  13. Switch r
  14. Switch n
  15. Switch p
  16. Switch i
  17. Switch o
  18. Switch l
  19. Switch L
  20. Switch t
  21. Switch e
  22. Switch u
  23. Switch g
  24. Switch a
  25. Conclusion

1. Introduction  Back to Top

I just noticed that there are no tutorials on /filter and would like to change that since it is a very useful command that many people can benefit from using. The amount of switches in the command may make it appear a little daunting so I will go through each of them and explain their purpose in detail. I recommend you try out the example commands given here as you read them, so you can have an idea of how everything works.

You will need:

  1. A custom window open at all times, for testing purposes.
    Type: /window -e @filter
    Now add a line of text to it, type: /aline @filter This is awesome
  2. A text file to work with. Let's leave it blank for now.
    Type: /write -c filter.txt
  3. A simple dialog with a listbox
    dialog filter {
      title "Filter"
      size -1 -1 400 400
      list 1,10 10 380 380
    }
    Type: /dialog -md filter filter
    Keep it minimized for the time being.

During the course of the tutorial I may to refer to windows/files and dialog listboxes different to the ones you now have open. This is simply to add variety and provide examples of /filter usage, you could always replace them with the names of other files/windows and listboxes.


2. The /filter command in detail  Back to Top

The command in full:

/filter [-asgdfwxnpriocteubglL] [n-n2] [c s] <INFILE dialog |> <OUTFILE dialog |> [alias] <MATCHTEXT>

I'll start with the basics and then go through each switch. With this command you must always specify a place to read from and a place to read to. These can be dialog listboxes, text files or mIRC's windows. What /filter does, at its simplest, is go through the place you selected to read from and copy lines over to the place you selected to read to. If no matchtext is given, it will filter all lines, for example:

/filter -wf @filter filter.txt

The switch "w" represents a window and "f" represents a file. The order of the switches is important, it is good practice to include them and have the infile switch before the outfile switch. You could leave out the switches and simply use /filter @filter filter.txt, leaving mIRC to interpret whether they're files or windows, however when it comes to dealing with channels, mIRC could get confused. So: always include the appropriate switches in the appropriate order.

In this case, the infile is @filter, the window to filter from, the outfile being filter.txt, the file to filter to. Because no matchtext is specified, it will copy every line over. Now let's suppose you only want to copy lines over that contain the word "succubus". This time we will attempt to copy from filter.txt to @filter:

/filter -fw filter.txt @filter *succubus*

Every line in filter.txt matching *succubus* is added to our @filter window. Because we have no lines in our filter.txt right now that contain that word, nothing will be added. However, if you had typed the first /filter example command I gave you, you would now have a line in the text file (remember /filter -wf @filter filter.txt that copied all lines from the window @filter into the file filter.txt?)
We can use this as an example. Type that command if you haven't already, then:

/filter -fw filter.txt @filter *is awesome

This will copy the line we had in filter.txt ("This is awesome") because the wildmatch "*is awesome" matches that line.

Note:

  • /filter will not create a window when you specify it as an outfile, it must already have been created.
  • It will, however, create files if they weren't already made.

    To re-cap:

  • Always specify the infiles/outfiles switches in the correct order.
  • /filter -fw filters from 'f'ile to 'w'indow
  • /filter -wf filters from 'w'indow to 'f'ile
  • When you have no matchtext, all lines are copied
  • When you do specify matchtext, only the lines that match it will be copied.

    This is subject to change depending upon what other switches and parameters you decide to use. But don't concern yourself too much with that now, instead try out some examples.


  • 3. Some Examples  Back to Top

    Example 1:
    Copy all lines from mIRC.ini into our @filter window
    /filter -fw mIRC.ini @filter
    Example 2:
    Create another window, @filter2, then copy only lines from @filter that begin with a open square bracket [
    //window @filter2 | filter -ww @filter @filter2 [*
    Example 3:
    Copy all lines from @filter2 that have the word "finger" in them to filter.txt and have the text file cleared before filtering to it
    /filter -cwf @filter2 filter.txt *finger*
    The "c" switch simply means that the outfile is cleared of its contents before the filtering begins.


    4. The Switches  Back to Top

    Now that we have established the basic method of using the command, and learnt that /filter is used to copy lines from one place to another, I can begin to explain the various switches of the command with different examples along the way.

    I will explain them in the following order and provide examples for each:

    -wfcsdpxbrniolLteuga


    5. Switch w  Back to Top

    This switch you came across before represents a window. This can be a channel window or a custom @Window.

    You can filter from a window to another window using the switches /filter -ww. You can even filter from a window to the same window by specifying it as both the infile and outfile. And, as I mentioned before, if you want to filter TO a window, it must be created. You can use list windows, normal windows or channels but not picture windows obviously.


    6. Switch f  Back to Top

    I also mentioned this one before, it represents a file, usually a txt file but not limited to it. Any file that can be used with $read can be used in /filter as they will yield the same results as far as reading the lines are concerned. /filter -fw will filter from a file to a window, -wf is used for a window to a file and you can even use -ff to filter from one file to another or even to itself. Contrary to windows, files will be created if they are specified as the outfile and do not exist.


    7. Switch c  Back to Top

    I explained this before briefly, although a brief explanation is all it needs. This switch simply clears the outfile before filtering to it, it's useful if you are filtering from a window to the same window (to sort something perhaps) so that you don't have a copy of every line as the behavior of the /filter command is to copy lines. So including "c" as a switch will have the outfile emptied before outputting lines.


    8. Some Examples  Back to Top

    Example 4:
    Filter the contents of versions.txt (if you don't have this just use any other text file) into @filter and have the window emptied beforehand:
    /filter -cfw versions.txt @filter
    Example 5:
    Keep only the lines in @filter that match *new* (so filter @filter to itself)
    /filter -ww @filter @filter *new*

    As you can see, it doesn't empty the window beforehand so the filtered lines as well as the whole of versions.txt is now in the window.
    Repeat Example 4 to get only the contents of versions.txt in the window.

    Example 6:
    Re-filter lines that match *new* in @filter but this time make sure the window is emptied before filtering
    /filter -cww @filter @filter *new*
    There, we are left with only lines that match *new*.


    9. Switch s  Back to Top

    This specifies the Status Window as either the infile or the outfile (or both) and it is treated just like any other window.

    If you want to use the status window as the infile (place to read from) to our custom window @filter, it's straight forward, you simply add the switches "sw" but do not include an infile like so: /filter -sw @filter (where @filter is the outfile).

    But if you want the Status Window as the outfile you still need to specify an outfile (it can be any text as long as it's there): /filter -ws @filter blabla. Similarly, if you wanted to filter from the Status Window to itself, you would use /filter -ss blabla.

    Example 7:
    Filter every line in the Status Window that ends with "Unknown command." into a file called unknown.txt
    /filter -sf unknown.txt *Unknown command
    Example 8:
    Load all lines from versions.txt into the Status Window
    /filter -fs versions.txt anytext
    Remember that the "anytext" can be anything, as long as it's in the command. This is only the case for when Status Window is the place to filter to, as mentioned above.
    Example 9:
    Remove all blank lines from the Status Window and keep the rest of them
    /filter -css anytext *?*
    The 'c' switch clears the Status Window in the process, so we don't end up with 2 copies of its contents (1 with empty lines and 1 without) and the matchtext *?* is telling mIRC to only keep lines with at least 1 character in them. ? is a wildcard that represents a single character.


    10. Switch d  Back to Top

    This works exactly the same as the 's' switch (see above) only it indicates to use the dedicated query window (or single message window) rather than the Status Window. This window, for those who aren't aware of it, is exactly as its name would suggest. It's a single window where all private messages from everyone are re-directed, an alternative to using multiple query windows. Anyway, should you want to filter to or from the single message window you can do so with the 'd' switch. /filter -dw @filter to filter from the dedicated query window to our @filter window. /filter -wd @filter anytext to filter from the @filter window to the dedicated query window (Like using the 's' switch, the "anytext" is mandatory but again can be any text you want as long as it's present).

    Type: /dqwindow on

    This will enable the dedicated query window. Send yourself some private messages just to fill the window up a bit and we can go through some examples.

    Example 10:
    Filter all lines that are not blank from information.txt to the dedicated query window
    /filter -fd information.txt anytext *?*
    The *?* matchtext as seen before ensures there's at least one character on the line being filtered.
    Example 11:
    Filter all lines in the dedicated query window that contain your nickname to a custom window called @MyMessages
    Remember to create the custom window first, /window @MyMessages
    /filter -dw @MyMessages $+(*,$me,*)
    The matchtext tells mIRC to look for your nickname anywhere in the line.
    Example 12:
    Filter the dedicated query window to itself, only keeping the messages that were sent between 3pm and 4pm (assuming your timestamp resembles [HH:...])
    /filter -cdd anytext [15:*
    This matchtext will only output lines that begin with [15: and the 'c' switch has the window cleared before outputting the filtered lines.


    11. Switch x  Back to Top

    Another simple switch to use, it tells mIRC to exclude the matching text. Where before we used matchtext to get what we want from a window/file we use the 'x' switch to get what we DON'T want. So if you have a file, stuff.txt, and you want to filter every line that doesn't contain "rude phrase" to the Status Window you would use /filter -xfs stuff.txt anytext *rude phrase* . It's as simple as that.

    Example 13:
    Filter all lines from #Funchat to our @filter window but exclude lines that contain "you suck"
    /filter -cxww #Funchat @filter *you suck*
    See, if we leave out the 'x' switch it will only filter lines that DO match *you suck* but by including the 'x' switch it filters lines that DON'T match it. The 'c' switch is used to clear the @filter window before filtering to it and 'ww' because we are filtering from a window (#Funchat) to another window (@filter)
    Example 14:
    Filter all lines from versions.txt into the Status Window and again exclude blank lines (different method)
    //filter -xfs versions.txt anytext $crlf
    Notice the 2 slashes before the command this time. This is because I want $crlf to be evaluated as it represents a blank line in a text file. By excluding all lines that match $crlf we are making sure we get no blank lines in the Status Window.
    Example 15:
    Remove all lines from #Meeting.log that start with -AnnoyingNoticer-
    /filter -cxff #Meeting.log #Meeting.log -AnnoyingNoticer-*
    Do you see why it is important to include the 'ff' switches when specifying 2 files as infile and outfile? mIRC may think it's a window (channel) otherwise. The 'f' switch forces mIRC to interpret it as a file, even if the filename is @Somefile.txt


    12. Switch b  Back to Top

    Like many of the other switches, 'b' doesn't require much of an explanation. What it does is disregard control codes in the infile when attempting to find a line that matches the matchtext. It does not strip the lines and output them as stripped lines, it just strips them...tries to match them with the matchtext...and then adds all control codes back in, so to speak. For example, if a line in a text file was: This is awe.4,1some. our earlier matchtext of *is awesome will not filter the line without the 'b' switch. It is recommended that you use this switch if you are filtering from a window that you are unsure has control codes in or not and you are not interested in the wildmatch matching the codes.

    Example 16:
    Filter only lines matching *code* from the channel #Scripting to a text file Scripting.txt and you want to disregard control codes in the match
    /filter -bwf #Scripting Scripting.txt *code*
    Example 17:
    Copy the lines in the dedicated query window that DON'T match *hello* to the Status Window, clearing the Status Window first as well as again disregarding control codes in the match
    /filter -cbxds anytext *hello*


    13. Switch r  Back to Top

    This switch specifies a range of lines to deal with in the infile. Looking back at the full /filter command:

    /filter [-asgdfwxnpriocteubglL] [n-n2] [c s] <INFILE dialog |> <OUTFILE dialog |> [alias] <MATCHTEXT>

    The parameter you see as "n-n2" is the range of lines, used with the 'r' switch. This is used to restrict the amount of lines in the infilfe to use in the filter process if for example you only want to use a certain range of lines for one reason or another. And because it restricts the filtering to only those lines in the range given, any others lines outside the range, regardless of whether they are matched by the matchtext, are ignored.

    Example 18:
    Filter only lines 56 to 87 of versions.txt to the Status Window
    /filter -rfs 56-87 versions.txt anytext
    Example 19:
    Filter lines 34 onwards from a channel called #Mychan to a new window @Mywindow
    //filter -wwr 34- $+ $line(#Mychan,0) #Mychan @Mywindow
    The range of lines specified is 34- $+ $line(#Mychan,0) where that $line identifier will returns the total amount of lines in that channel. So that is basically telling mIRC to filter from line 34 to the last line (No, 34- is not a valid range so you must use that).
    Example 20:
    Filter the last 20 lines in the dedicated query window to a file called new.txt but don't filter lines that have the word "smelly" in them
    /filter -rxdf $calc($line(Message Window,0) - 20) $+ - $+ $line(Message Window,0) new.txt *smelly*
    Here we see the 'x' switch again, telling mIRC to exclude all lines that are matched by our matchtext of *smelly*. The calculations in there are to find the last line number minus 20 so we can specify the range of lines. $line(Message Window,0) returns all lines in the dedicated query window, line number 1 is the first line that was added to the window.


    14. Switch n  Back to Top

    This switch will prefix each line that is filtered into the outfile with the line number it was in the infile. So, if I filter a text file to a window with specific matchtext and lines 17, 23 and 65 are the only lines that are matched and filtered to the window, it will prefix the line with 17 23 & 65. This can be useful when you're sifting through many lines in a window looking for specific text. With a quick /filter you can have the matching lines in another window along with the line numbers of each line next to it which then makes it easy for you to refer to the first window's lines with $line to get what you want.

    Example 21:
    Filter all lines with the word "Sigh_" in them from #Scripting to @Mynick prefixed with the line numbers of matching lines
    /filter -nww #Scripting @Mynick *Sigh_*
    Example 22:
    Filter all blank lines in versions.txt to a window called @Linenumbersofblanklinesinversions.txt with the line number prefix
    //filter -nfw versions.txt @Linenumbersofblanklinesinversions.txt $crlf
    Remember the 2 slashes in the filter command so $crlf is evaluated and used as matchtext.
    Example 23:
    Filter only lines 10-30 in the dedicated query window with their line number prefixes that DON'T contain the word "newbie" to @filter
    /filter -nxrdw 10-30 @filter *newbie*
    Starting to get a good idea of how to incorporate these switches into filtering what you want? Good, there's more to come.


    15. Switch p  Back to Top

    This is a simple switch to get the hang of. It has the same function as using /aline -p in the way that it wraps the line in the outfile window. This is used in case you are reading from a txt file where the lines are very long. If you filtered without the 'p' switch then you would not see the whole line, just as much as the width of the window allows you to. To see an example of what I mean, type: //window @Test | aline @Test $str(bla,100)

    As you can see, the whole line does not show up. Now try //window @Test | aline -p @Test $str(bla,100) and notice the difference. The line is wrapped in the window, allowing you to see all of it. The 'p' switch in /filter has the exact same effect which makes reading long lines more manageable.

    Example 24:
    Filter all lines from #Mychan into @filter with wrapping so we can see the full lines
    /filter -pww #Mychan @filter
    Example 25:
    Filter all lines from longlines.txt into @Smallwindow that don't contain "h4x0r", include line number prefixes and line wrapping
    /filter -pxnfw longlines.txt @Smallwindow *h4x0r*
    Example 26:
    Filter lines 45-60 from versions.txt into @filter with line wrapping, number prefixing, and only lines that match "hello" followed by a space and at least 3 characters
    //filter -rpnfw 45-60 versions.txt @filter $+(*hello,$chr(32),???*)
    The question marks in the matchtext represent a single character.
    You should be noticing by now that when you have a specific purpose for /filter all it takes is a little logic and you can determine the appropriate switches quickly.

    16. Switch i  Back to Top

    This switch allows you to specify a dialog listbox as the infile. Since listboxes use lines like a window or text file does, so too can they be used in filtering. You can specify matchtext and use any of the other switches with it. An example of how the 'i' switch is used is: /filter -iw mp3player 4 @List which will filter everything from the listbox ID 4 in the dialog called 'mp3player' to the window @List. You must specify a dialog name and ID with this switch.

    Example 27:
    Save the contents of a listbox ID 3 in a dialog called "jukebox" to favorites.txt, making sure the text file is cleared before outputting to it
    /filter -cif jukebox 3 favorites.txt
    Example 28:
    Another similar song list, this time we don't want to save the songs that are in C:\Music\Awful\
    /filter -xcif jukebox 3 favorites.txt *C:\Music\Awful\*
    Example 29:
    Filter lines 33 to the 5th last line in a listbox ID 2 in a dialog called "food" to the Status Window, excluding all lines that begin with "chicken"
    /filter -xris 33- $+ $calc($did(food,2).lines - 4) food 2 anytext chicken*
    (To find the 5th last line we subtract 4 from the total amount of lines). If you are unsure of any of the switches being used, scroll back up to their explanations above and refer back to them to refresh your memory.


    17. Switch o  Back to Top

    This is similar to the previous switch 'i' but this time it specifies a dialog listbox as the outfile. A simple example would be /filter -wo @Files sighs 5 which would copy all lines from the window @Files to the listbox ID 5 in the dialog "sighs". You can even of course filter a dialog listbox to itself using -io as switches.

    Example 30:
    Filter every line from the Status Window into the listbox ID 6 in "dialog1", clearing its contents beforehand
    /filter -cso dialog1 6
    Example 31:
    Filter all lines from the dedicated query window ending with "66" to our original dialog "filter", listbox ID 1. Have each line prefixed with the line number
    /filter -ndo filter 1 *66
    Example 32:
    Remove from the listbox ID 9 in the dialog "scripts" every line that has the word "funky" in it
    /filter -cxio scripts 9 scripts 9 *funky*


    18. Switch l  Back to Top

    We are approaching the end of the infile/outfile switches. The 'l' switch (Small letter L) let's you use a window's side listbox as the infile. The window can be a channel, (its side listbox being the nicklist) or a custom window with a side listbox being defined in the /window -lN command. Referring to the side listbox of a channel window will give you each nickname on each line (as you would see it by looking at the nicklist). The side listbox in a custom window's lines would be those that were added to it via /aline -l

    Example 33:
    Filter the nicklist in the channel #Filter to a custom window called @#Filter_nicknames
    /filter -lw #Filter @#Filter_nicknames
    Example 34:
    Filter every nickname in the nicklist of #Scripting except the ops to a text file called nicklist.txt overwriting any existing information in the file
    /filter -cxlf #Scripting nicklist.txt @*
    Example 35:
    Filter all items in a custom window (@Win)'s side listbox that end with "Bot" to the dedicated query window, prefixing each line with its line number
    /filter -nld @Win anytext *Bot


    19. Switch L  Back to Top

    This switch works very similar to the previous one, only it lets you use a custom window's listbox as an outfile. This cannot be used to filter to a channel listbox just to a custom window's. If you use the 'L' switch to filter to a window without a listbox, the output will go to the window as it would if you used the 'w' switch. You can of course filter from a listbox to itself using -lL as switches.

    Example 36:
    Filter lines 34-65 from the Status Window to the listbox of @Filter, prefixing each with their line numbers and clearing the listbox before outputting
    /filter -cnrsL 34-65 @Filter
    Example 37:
    Filter lines that DON'T contain "mIRC" from the channel #Newbs to the listbox of @Sbwen, disregarding all control codes when matching text
    /filter -xbwL #Newbs @Sbwen *mIRC*
    Example 38:
    Filter the listbox of @Filter to itself, removing all blank lines in the process
    /filter -clL @Filter @Filter *?*


    20. Switch t  Back to Top

    This switch allows you to sort the output based on a specific token in the lines. You must supply the filter command with 2 extra parameters when you use this switch. A column number (C) and separator (S). For example, if each line that was being filtered was of the format:

    number name text here

    And you wanted to sort it based on the "name", you would choose to filter it based on the second token delimited by character 32 (a space). So it is linked to $gettok in the way that you are sorting it based on $gettok(line,C,S) where C is the column number and S is the ascii number of the separator/delimiter. If my line looked like this:

    name!number!text here

    And I again wanted to sort it by name by column number, C, would be 1. My separator (exclamation mark) would be number 33. So I would use /filter -t 1 33

    When in doubt, just think back to $gettok and see what you would need to include to get the token you want to sort by. Without using any extra switches linked to sorting (such as the ones I will explain next in the tutorial), this will sort in alphabetical order. Hence using numbers in this sort will show 9 being after 1,000 in the order because the '1' in 1,000 is before '9' when sorting alphabetically.


    21. Switch e  Back to Top

    Before I move on to examples of the 't' switch I will just explain the switch 'e'. All it does is sort lines in descending order because, by default, lines will be sort in ascending order. This makes it ideal for ranking systems, as you get the larger numbers first.

    Example 39:
    We have lines that look like this in a window: word1:word2:word3 word4 onwards
    We want to sort these lines by "word2", alphabetically, from a window called @Mess to a text file called tidy.txt.
    /filter -twf 2 58 @Mess tidy.txt
    Notice the '2 58' used here with the 't' switch to sort the lines based on the second token separated by $chr(58) (a colon).
    Example 40:
    We have lines that look like this in a window: word1:word2:word3 word4 onwards
    We want to sort these lines by "word2", alphabetically, from a window called @Mess to a text file called tidy.txt.
    /filter -twf 2 58 @Mess tidy.txt
    Notice the '2 58' used here with the 't' switch to sort the lines based on the second token separated by $chr(58) (a colon).
    Example 41:
    Now, in the listbox of a window called @Hosts, we're dealing with lines of the format: number nick!ident@host
    And we want to filter only lines 1-50 to the listbox of @Hosts1, then the rest to the listbox of @Hosts2 sorting alphabetically ascending, by "ident". For the filter to @Hosts2 we want to disclude any hosts that end with aol.com
    //filter -rtlL 1-50 2 33 @Hosts @Hosts1 | filter -xrtlL 51- $+ $lines(@Hosts,0,1) 2 33 @Hosts @Hosts2 *aol.com
    As you can see, we need 2 filter commands to filter to the 2 windows, obviously.
    The range of lines in the second command is 51-<TOTAL @Hosts of listbox the in lines>


    22. Switch u  Back to Top

    This switch works with the 't' switch and specifies a numerical sort. So unlike before, 1,000 this time is past 9 in the order since it is a larger number. The 'u' switch is ideal for generating rankings, for example, an mp3 rank system. Anytime you are dealing with amounts/a number of something, and want to filter using that as a sort, use this switch.

    Example 42:
    A typical mp3 ranking system, lines in a file called mp3rank.txt look like this: timesplayed C:\path\to\song..
    A rank based on the times played must be generated in the window @Mp3rank to show the most popular songs. (So it must be a descending sort, to get the higher numbers at the top)
    /filter -teufw 1 32 mp3rank.txt @Mp3rank
    Notice how we're using all of the sorting switches, because we want a descending numerical sort.
    Example 43:
    The lines in a dialog called "cheesy"'s listbox of ID 3 look like so: nickname|power
    Where "power" is a number denoting a nickname's power. These lines are to be filtered to the side listbox of a window called @Literf, sorted ascendingly based on power preceeded by their line numbers. We also want to filter over the existing lines in the listbox.
    /filter -cntuiL 2 124 cheesy 3 @Literf


    23. Switch g  Back to Top

    This handy switch signals that you are using a regular expression as the matchtext. So, it is as if you are using $regex(line,matchtext) and if this returns 1 the line will be filtered since the matchtext is met. If the line doesn't match the pattern specified by the regex then it will return 0 and the line will not be filtered. If you do not know regular expressions then there's no use in trying to understand the ones in the following examples, though you can still try them out if you wish.

    Example 44:
    Filter all lines from the Status Window that signal an error in a command or identifier (For example, * /echo: insufficient parameters) to errors.txt
    /filter -gsf errors.txt ^\*\s[/$]\S+:\s.+
    Example 45:
    Using only lines 22-67 of the dedicated query window, filter every line where the person messaging you has NOT used control codes in the third word, to a listbox ID 15 in a dialog called "Messages", clearing the outfile beforehand.
    /filter -cxrgdo 22-67 Messages 15 ^\S+\s\S+\s\S*[[:cntrl:]]


    24. Switch a  Back to Top

    The final switch to learn of the filter command, this will have the output sorted by calling a custom identifier. mIRC then compares each line with every other line so it can determine each line's position in the outfile. This is where the alias comes in. The alias is given the first line as $1 and the second line as $2. It then compares the 2 lines and returns either "1" ($1 is in front of line $2 in the order) or "-1" ($1 is behind line $2 in the order) or "0" (The two lines should have the same ordering). To put it simply, this switch allows you to use an identifier to sort lines, where each line is compared with each other until the position of every single line is determined.

    This is useful because it allows you to use other things when ordering lines (such as the length of a line) or even the filesize of a file included in the line (as I am about to show in the example).

    Example 46:
    Sorting mp3s in the folder C:\mp3s by filesize and having them put in a dialog called "Mp3s" listbox ID 1 in ascending order
    First of all, we need an alias for use in the filter command:
    
    alias sortfiles {
    var %1 $file($1),%2 $file($2)
    return $iif(%1 > %2,1,$iif(%1 < %2,-1,0))
    }

    As you can see, $1 and $2 will be the filenames of mp3s. If the filesize of $1 is greater than $2, $1 is to be further up in the order. If not, then $2 is to be further up and if the filesizes are equal, 0 is returned (the same order).
    Now we need the list of mp3s in the dialog listbox, this can be done using $findfile:
    //.echo -q $findfile(C:\mp3s,*.mp3,0,did -a Mp3s 1 $1-)
    Now that we have our list we are ready to begin the filtering:
    /filter -aio Mp3s 1 Mp3s 1 sortfiles
    And there we go, the mp3s should be sorted in the dialog listbox in ascending order of filesize.


    25. Conclusion  Back to Top

    Ok, all the switches have been covered. One last thing: the $filtered identifier can be used after the filter command to return the amount of lines that were filtered by the last call to /filter. I hope by now that you have read and understood most of what is included in here, and that you can find productive ways to include /filter in your own scripts. If anyone has anymore good examples of the command since I will be adding to this tutorial including the examples here, at the end, feel free to e-mail me with your username and example/s.