Category : Dbase (Clipper, FoxBase, etc) Languages Source Code
Archive   : DB_DIREC.ZIP
Filename : TREESRCH.PRG

 
Output of file : TREESRCH.PRG contained in archive : DB_DIREC.ZIP


* Program..: TREESRCH.PRG
* Author...: DAVE KAHN
* Date.....: 5/7/90
* Notice...: Copyright (c) 1990, Dave Kahn (301)333-3417
* Notes....: A demonstration program for searching all directories on a
* Notes....: hard disk. Displays all found files and directories on
* Notes....: screen. The procedure "f_action.prg" is responsible for action
* Notes....: taken on each file found (which in this case is displaying
* Notes....: the path and filename on screen).
* Notes....: TYPE_SRCH defines the files found. 16 (binary 10000) gives
* Notes....: directories. Bits 1-4&6 control other attributes.
* Notes....: You can find out about the parameters of db_dir by running
* Notes....: it with no parameters.

set talk off
set echo off
set step off
set status off
close all
clear

type_srch = 0
search_no = ''
bit5 = .t. && Subdirectory search
rhs = .f.
bit6 = .f.
bit4 = .f.
bit3 = .f.
bit2 = .f.
bit1 = .f.
archive = .f.
m_disk='C'
sel_path=' '
init_path=''
fn_temp = '*.* '
store .f. to abort
m_path=''
maxpathno=0
m_current=0
m_initial=0
store .f. to init_found && True if the initial dir is in the file PATHS.DBF.
store .t. to continue
store .f. to done
store .f. to dirs
store .t. to new

if .not. (file('paths.dbf').or.file('pathform.dbf'))
@14,14 say "File PATHFORM.DBF is not in the current directory."
store .t. to abort
endif
if .not. file('db_dir.exe')
@14,15 say "File DB_DIR.EXE is not in the current directory."
store .t. to abort
endif
if abort
return
endif

do while .not. done
@ 6,8 say "Enter the letter of the hard disk to search: " get m_disk
read
@ 8,12 say "Enter the starting path for the search: " get sel_path
read
@ 10,12 say "Enter the filename template in search: " get fn_temp
read
if len(trim(sel_path)) > 0
if substr(trim(sel_path),1,1) # '\'
sel_path = '\'+trim(sel_path)
endif
if substr(trim(sel_path),len(trim(sel_path)),1) # '\'
sel_path = trim(sel_path)+'\'
endif
init_path = upper(trim(sel_path))
else
init_path = '\'
endif
done = .t.
fn_temp = trim(fn_temp)
@ 12,12 say "The path you selected is " ;
+trim(m_disk)+':'+init_path+fn_temp
@ 14,12 say 'Is that correct(Y/N)? ' get done picture 'Y'
read
if done
clear
@ 10, 23 say "Search all subdirectories? " get bit5 picture "Y"
read
@ 12, 6 say "Include read-only, hidden, and system files? " ;
get rhs picture "Y"
read
if rhs
bit1 = .t.
bit2 = .t.
bit3 = .t.
endif
@ 14, 6 say "Include volume names? " get bit4 picture "Y"
read
@ 16, 6 say "Process only 'archive' files? " get archive picture "Y"
read
type_srch = 16*iif(bit5,1,0)+iif(bit1,1,0)+2*iif(bit2,1,0)+4*iif(bit3,1,0)+8*iif(bit4,1,0)
search_no = ltrim(str(type_srch))
@ 18, 25 say "Continue? " get continue picture "Y"
read
clear
if .not. continue
return
endif
endif
enddo
clear
m_path=init_path && Start search at specified directory

** Prepare the PATHS file:

select a
if .not. file('PATHS.DBF')
copy file pathform.dbf to paths.dbf
endif
use PATHS
if .not. (file('path.ndx').and.file('pathno.ndx'))
index on path to path.ndx
index on pathno to pathno.ndx
endif
set index to path.ndx, pathno.ndx order path.ndx
set order to 1
set filter to DISK=m_disk
set exact on
go top
do while .not. eof()
replace SEARCHED with .F., FOUND with .F. && Initialize database.
if PATHS->PATH=init_path
store PATHNO to m_current && Get path number of this path from file.
store .t. to init_found
m_initial = m_current
endif
if PATHNO > maxpathno
maxpathno = PATHNO && Set maxpathno at the highest path no.
endif
skip
enddo
if .not. init_found && Add the path to the PATHS file if not in it.
maxpathno=maxpathno+1
m_current=maxpathno
m_initial=m_current
append blank
replace DISK with m_disk
replace PATHS->PATH with init_path
replace PATHNO with m_current
replace SEARCHED with .F., FOUND with .T.
endif

go top
store .f. to done
store .t. to new && Initialize search
do while .not. done
* Run this loop for each path found.

* Run a DB_DIR on paths not searched. DB_DIR creates the file cur_dir.dbf
* as specified in its command line. DB_DIR uses "findfirst" and
* "findnext" DOS functions to search the specified directory.

if new && If not searched yet
select b
use
erase cur_dir.dbf
run db_dir.exe cur_dir.dbf &m_disk:&m_path.&fn_temp &search_no
if .not. file('cur_dir.dbf')
close databases
return
endif
use cur_dir.dbf
if archive
set filter to (DIR .or. ARCH)
endif
store .f. to new
go top

* Look for subdirectories.
store .f. to m_subs && Assume this dir has no subdir's.

* Search for directories found in cur_dir.dbf and append found
* directories to PATHS.DBF. Each loop checks one record of cur_dir.

do while .not. eof()
if DIR .and. len(trim(FILENAME))>0 && This dir has a subdir.
store .t. to m_subs
if len(trim(EXT))>0
new_path = trim(CUR_DIR->PATH)+trim(FILENAME)+'.'+trim(EXT)+'\' && Name of subdir. path
else
new_path = trim(CUR_DIR->PATH)+trim(FILENAME)+'\'
endif
select paths
set order to 1
go top
seek new_path
if .not. found() && add new dir to paths.dbf
append blank
maxpathno=maxpathno+1
replace PATHS->PATH with new_path
replace PATHNO with maxpathno
endif
replace FOUND with .T.
replace SEARCHED with .f.
replace PARENT with m_current
replace DISK with m_disk
select cur_dir
else
do f_action && Take action on files found.
endif
skip
enddo
endif

* Switch to the next subdirectory by changing m_path and m_current var's

select paths
set order to 2 && Index is PATHNO
go top
if m_subs

* Look for the next child to the current directory that has not been
* searched:

do while (.not. new).and.(.not.eof())
if (PARENT=m_current).and.(FOUND.and.(.not.SEARCHED))
store PATHNO to m_current && Switch to subdir
store trim(PATH) to m_path
store .t. to new
else
skip
endif
enddo
endif
if eof() .or.(.not. m_subs) && If there are no more subdirs found
go top && or there never were
seek m_current
replace SEARCHED with .T.
if m_current = m_initial && This is the original dir; you're done.
store .t. to done
else
m_current = PARENT && Switch back to the previous dir.
go top
seek m_current
m_path = trim(PATH)
store .t. to m_subs && This parent may have other children.
endif
endif
enddo
set exact off
close databases
return