Here is another program that works equally well with JB as with LB except for the SORT function you will notice is not available with JB, and had to be disabled in this version. If you consider a sorting routine of particular importance it is a simple matter to include it manually. Many looking at this program will no doubt soon realize it basically performs the same functions as are already available with Windows. It searchers selected files for the occurrence of selected text, or provides a list of all files in a directory, or only those with the same .EXT as the one selected. But so far as I can see the boffins at Microsoft have never had the foresight to allow us to save a list of these functions, let alone a cumulative list of files in a variety of Directories as possible this little program.
Let us study a few points that might be of special interest. Notice I have abandoned any attempt to make the program compatible with screen displays of less than 1024 wide. You can easily change such as by reducing colm > 900 in the [show] section etc. Note the use of fill white some clever guy contributor pointed was needed to ensure a graphics screen could be scrolled without losing data shown. The REDIM is needed in the [new] section when a RESELECT button is activated before moving onto [files]. Those looking at previous programs of mine will recognise the way DIR.BAS supplied with LB has been adapted, which also works equally well with JB if again the SORT is disabled. Notice how which files are listed is either determined by the .EXT of a selected file or whether ALL has been entered, and the use of UPPER$ to prevent any problems. TOT is used to allow more files to be added from another Directory providing FILE SEARCH is not chosen. Once a list of files has been created for ITEM$(N) they are copied into FOUND$(N), which is really unnecessary when FILE SEARCH is chosen, since FOUND$(N) is needed to collect details of a successful search of each file. This is why [new] is used to activate REDIM etc with FILE SEARCH.
In the [show] section depending on whether a File Search is in action decides whether ITEM$ or FOUND$ is displayed. The section [more] is used to add to the list of files, something Windows is incapable of doing by showing a list of files in more than one directory. Note how at the end of the [files] section the PATH$ is added a the start of a list and the number of files on TOT at the end of the list.
nomainwin : disp$ = "SORRY ONLY FOR LARGER SCREEN DISPLAYS!"
dim item$(1010):dim found$(1010):dim dir$(10,3):dim info$(1, 1)
if DisplayWidth < 1000 then notice disp$ : end
WindowWidth = 1024
button #1, "File Search", [search], ul 180, 650
button #1, " Reselect ", [new], ul 330, 650
button #1, "Add to List", [more], ul, 480, 650
button #1, "Save List/s", [save], ul, 630, 650
button #1, " ** Quit **", [quit], ul, 780, 650
open "Files search" for graphics_fs as #1
#1 "trapclose [quit]; down; fill white" ' FILL NEEDED TO ALLOW SCROLLING
#1 "font arial 14 bold; color darkblue; place 280 50"
#1 "\This will either scan files in any Directory for any text"
#1 "\or provide lists of files in one or more Directory. You"
#1 "\select all the files by entering ALL, or only those with"
#1 "\the same .EXT as the actual file your select."
tot = 0 : playwave "beep"
#1 "font fixedsys; color black; flush"
wait
[new]
redim item$(1010) : redim found$(1010) : #1 "cls"
[files]
DefaultDir$ = left$(DefaultDir$,2)+"\" ' START FROM ROOT
filedialog "Pick by Ext or enter ALL","*.*",File$
if File$ = "" then [quit]
File$ = upper$(File$)
type$ = "*." + right$(File$,3) ' SEARCH BY SAME .ext
if right$(File$,3) = "ALL" then type$ = "*.*"
sFile$ = noPath$(File$)
plen = len(File$)-len(sFile$)
path$ = left$(File$,plen)
files path$, type$, dir$()
qtyFiles = val(dir$(0, 0))
if qtyFiles > 999 then
notice "list limited to 1000" 'SET BY DIM (1010)
qtyFiles = 999
end if
for x = 1 to qtyFiles
ts$ = left$(dir$(x, 0) + " ", 50)
item$(x) = trim$(ts$)
next x : n = 1
'sort item$(), 1,qtyFiles ' ALPHA SORT only with LB
found$(tot+1) = path$
for add = tot + 2 to tot + qtyFiles+2
found$(add)=item$(n) : n = n + 1
next add
tot = tot + qtyFiles+1
found$(tot)="TOTAL = ";str$(qtyFiles)
return
[show]
#1 "cls" : row = 20 : colm = 10
for z = 1 to tot ' LIST ALL BY .ext
#1 "place ";colm;" ";row
if search = 0 then #1 "|";z;" ";left$(found$(z),16)
if search = 1 then #1 "|";z;" ";left$(item$(z),16)
colm = colm + 165
if colm > 900 then colm = 10 : row = row +14
next z : #1 "flush"
return
[search]
redim item$(1010) : redim found$(1010) : search = 1
gosub [new] : tot = qtyFiles : gosub [show]
#1 "flush; color blue" : row = row + 14
prompt "Enter text to be found";text$
if text$="" then wait
cas = 1 : confirm "Ignore upper/lower case?";q$
found=0 : if q$ = "yes" then cas=0 : text$=upper$(text$)
for file = 1 to qtyFiles
#1 "place 350 ";row : #1 "\SEARCHING FILE No. ";file
tfile$=path$+item$(file)
open tfile$ for input as #f
ok=0 : while ok=0
if EOF(#f) < 0 then ok = 1 : goto [done]
line input #f, test$
if cas = 0 then test$=upper$(test$) 'IF CASE IGNORED
if instr(test$,text$)>0 then
found = found + 1
found$(found) = item$(file) : ok = 1
end if
[done] wend : close #f
next file
#1 "place 350 ";row
#1 "\'";text$;"' FOUND IN THE FOLLOWING ";found;" "
row = row + 14 : colm = 10
for z = 1 to found
#1 "place ";colm;" ";row
#1 "\";found$(z)
colm = colm + 165
if colm > 900 then colm = 10 : row = row +14
next z
wait
[save]
#1 "flush"
filedialog "Create txt file to store list", "*.txt", F$
if F$ = "" then wait
if search = 0 then last = tot else last = found
open F$ for output as #s
for n = 1 TO last
#s n;" ";found$(n)
NEXT : close #s : notice "FILE " + F$ + " SAVED."
wait
[more]
gosub [files] : search = 0 : gosub [show] : wait
[quit]
close #1 : end
function noPath$(t$)
while instr(t$, "\")
t$ = mid$(t$, 2)
wend
noPath$ = t$
end function