I asked several people on how to search a TXT file in 4DOS and got many
responds. I think most of them deal with linear search which is very slow! Since
my txt file contained all filenames which are already sorted, so I figure the
best way to do this is with binary search.

Here is what I got after translated a routine from PASCAL to 4DOS:

    setlocal
    iff "%1" eq "" then
        input Type in filename to search: %%filename
    else
        set filename=%1
    endiff
    set filename=%@lower[%filename]
    set file=DOWNLOAD.DAT
    set bottom=1
    set top=%@lines[%file]
    if %top lt 0 quit 2

:LOOP
    iff %top GT %bottom then
        set middle=%@int[%@eval[(%top+%bottom)/2]]
        set linein=%@lower[%@line[%file,%middle]]
        iff %filename EQ %linein then
            endlocal
            quit 1
        elseiff %filename GT %linein then
            set bottom=%@eval[%middle+1]
        else
            set top=%middle
        endiff
        goto loop
    endiff

    iff %top EQ 0 then
        endlocal
        quit 2
    elseiff %filename EQ %linein then
        endlocal
        quit 1
    else
        endlocal
        quit 2
    endiff

------------

It is not perfect yet but it does work!
I used this routine to check for a filename in DOWNLOAD.DAT to see if I already
downloaded a file or not. It's very useful if you are collecting GIFs!!!

If you think you can make it work better, please do just that and let me know.

Thank

