FILE SEARCH AND SCAN

by Gordon Sweet
http://sionet.mysite.wanadoo-members.co.uk/LBcode.htm

If like me you are of the curious type, and sometime like to safely scan through some obscure file to try to find its purpose by reading any readable text within, then you might find this program of some use. Since it only reads the file, I have never known this method to activate or corrupt a file.

There are two options of how to locate a file. One uses Mark Parkinson’s clever search routine of all the hard drive by chosen EXT, and the results are shown in Notepad. This has advantage of the Search or Find option provided by Windows, in that you can printout, copy of save the results. I have never fathomed out why MS have never thought to provide such facilities, or have I missed it somewhere? By making a note of the number given to any file on the file list, you can then run the file through the scanner. The second option simply goes straight to the Filedialog to select a file. With each option you have the option to select another file before quitting.

This is one program that works equally well with Liberty Basic or Just Basic as it uses no API calls.

' With acknowledgents to Mark Parkinson for the Recursive Files routine
    nomainwin
    note$ = "Program needs screen width of alt least 1024"
    if DisplayWidth < 1000 then notice note$: end
    open "FILE SEARCH AND SCAN" for graphics_fs_nsb as #s
    #s "trapclose [quit]; font arial 24 bold; place 400 100; down"
    #s "\FILE SEARCH" : #s "font arial 14 bold; place 250 200"
    #s "\This will safely scan any file and display all the readable"
    #s "\bytes. Enter the ext of files to be found, such as INI, then"
    #s "\wait for a list to be created, or enter / to use the filedialog"
    #s "\for a file. The CANCEL button will quit the program."
    #s "flush": playwave "chord" : dim F$(10000) : dim Q(11)
    tim = time$("ms"):while time$("ms")""
        p=instr(list$,"*")
        p$=left$(list$,p-1)
        call recurse p$,mask$ 
        list$=mid$(list$,p+1)
    wend
    end sub

[view]
    C = Q(1) ' temp file needed to store results
    open "temp.$$$" for output as #t
    for n = 1 to C
        #t n;" : ";F$(n)
    next n : close #t
    ' display using notepad
    run "notepad.exe temp.$$$",showmaximized
    playwave "chimes"
    kill "temp.$$$" ' DELETE TEMPORARY FILE
[item]
    prompt "Enter the number of the the file to scan";n$
    nf=val(n$) : File$=F$(nf):pick=0 : if nf=0 then [quit]
    if nf > C then notice "MAXIMUM FILE FOUND = ";C: goto [item]

[show]
    close #s : txtX = DisplayWidth/2 - 300
    button #s, "Next Page ", [cont], LL DisplayWidth-100, 80
    button #s, "Abort View", [fin], LL DisplayWidth-100, 40
    open "Scan" for graphics_fs_nsb as #s
    #s "trapclose [quit]; cls; color black; place 20 12"
    maxX = 96/800*DisplayWidth : maxY = DisplayHeight -80 : scn = 0

[which]
    DefaultDir$ = left$(DefaultDir$,2)+"\" ' START AT ROOT DIRECTORY
    #s "cls; font fixedsys; color red; place 20 12"
    #s "\**** WAIT FOR COMPLETION OF SCANNING ****"
    #s "flush" : text$="\" : newline = 0
    if pick=1 then filedialog "ANY FILE!","*.*",File$
    if File$ = "" then [quit]
    confirm "Accept Line Breaks?"; nl$
    if nl$ = "yes" then newline = 1

[file]
    #s "|FILE = ";File$
    #s "color black" : scn = 1
    open File$ for input as #scn
[read]
    scan : if eof(#scn) <> 0 then [fin]
    dat$ = input$(#scn, 1) : chr = asc(dat$)
    ' avoid / line break with LB code
    if dat$ = "\" or dat$ = "|" then dat$ = "/"
    if newline = 0 then [miss]
    if chr = 10 then #s text$ : text$ = "\" 'new line
[miss]
    ' Accept only CHR$ 32  to 126
    if chr > 31 and chr < 127 then text$ = text$ + dat$ 
    if len(text$) > maxX then ' width of Display
        print#s, text$ 
        text$ = "\" ' ready for new line
    end if
[next]
    #s "posxy x y"
    if y > maxY then gosub [halt] ' height of Display
    goto [read]

[fin]
    if File$ = "" then [quit]
    close #scn : scn = 0 : #s text$ 
    confirm "SCAN COMPLETED - Another File ?"; q$
    if q$ = "no" then [quit]
    if pick = 1 then goto [which]
    prompt "Enter the number of the the file to scan";n$
    nf=val(n$) : File$=F$(nf)
    if nf=0 then [quit] else goto [which]

[halt]
    playwave "anywav"  : wait ' next page ?
[cont]
    #s "cls; color black; place 20 12" : goto [read]

[quit]
    if scn = 1 then close #scn
    close #s : end