I have written a function to scan a folder and all sub-folders for files of a particular kind and save the list to a seperate file. It works but doesn't always perform the same way each time it is run. I will (seemingly randomly) do one of four things:
1) Shrink the DBP window to the taskbar and keep the progress window open (which is what I want)
2) Shrink both windows
3) Keep the DBP window open but not show the progress window
4) Crash with an unknwon error.
Any help would be appreciated.
Thanks
Here is the folder scan code:
#Constant cYES 1
#Constant cNO 0
#Constant cFILE 0
#Constant cDIR 1
startBlue "##", "####"
BackDrop On
sync on
Global gMain
Global TotalFound
Global Cx
Global Cy
Cx = Display width() / 2
Cy = Display Height() / 2
gMain = Get DBPRO Window()
CreateUI()
t = timer()
ScanFolders( "c:Media3d Models", "dbo" )
time = ( timer() - t ) / 1000
do
text 0, 0, "Time Taken: " + str$( time ) + " Seconds"
text 0, 20, "Found : " + str$( TotalFound ) + " items"
sync
loop
end
`===========================
` SCAN FOLDERS
`===========================
function ScanFolders( StartPath as string, Extension as string )
minimise window gMain
restore window gSearchingWindow
set Active Window gSearchingWindow
bringToFront gSearchingWindow
f$ = "List.txt"
if file exist( f$ ) then delete file f$
Open to write 1, f$
setGadgetVisible gSearchingWindow, cYES
cd StartPath
dim CQ( 0 )
dim Count( 0 )
D = 0
Count( D ) = 1
perform checklist for files
CQ( D ) = checklist quantity()
repeat
repeat
perform checklist for files
d$ = get dir$()
split string d$, ""
d$ = get split word$( split count() )
setGadgetText gSearchLabel, "Searching in directory: " + d$
select checklist value a( Count( D ) )
case cFILE
if right$( checklist string$( Count( D ) ), 3 ) = Extension
setGadgetText gFound, "Found: " + remove$( checklist string$( Count( D ) ), Extension )
inc TotalFound
setGadgetText gTotal, "Total: " + str$( TotalFound )
write string 1, get dir$() + checklist string$( Count( D ) )
endif
endcase
case cDIR
if left$( Checklist string$( Count( D ) ), 1 ) <> "."
cd checklist string$( Count( D ) )
inc D
add to queue Count( 0 )
add to queue CQ( 0 )
perform checklist for files
CQ( D ) = checklist quantity()
Count( D ) = 1
repeat
perform checklist for files
select checklist value a( Count( D ) )
case cFILE
if right$( checklist string$( Count( D ) ), 3 ) = Extension
setGadgetText gFound, "Found: " + remove$( checklist string$( Count( D ) ), Extension )
inc TotalFound
setGadgetText gTotal, "Total: " + str$( TotalFound )
write string 1, get dir$() + checklist string$( Count( D ) )
endif
endcase
case cDIR
if left$( Checklist string$( Count( D ) ), 1 ) <> "."
cd checklist string$( Count( D ) )
d$ = get dir$()
split string d$, ""
d$ = get split word$( split count() )
setGadgetText gSearchLabel, "Searching in directory: " + d$
inc D
add to queue Count( 0 )
add to queue CQ( 0 )
perform checklist for files
CQ( D ) = checklist quantity()
Count( D ) = 1
endif
endcase
endselect
inc Count( D )
until Count( D ) = CQ( D ) + 1
cd ".."
dec D
d$ = get dir$()
split string d$, ""
d$ = get split word$( split count() )
setGadgetText gSearchLabel, "Searching in directory: " + d$
endif
endcase
endselect
inc Count( D )
until Count( D ) = CQ( D ) + 1
repeat
cd ".."
dec D
inc count( D )
d$ = get dir$()
split string d$, ""
d$ = get split word$( split count() )
setGadgetText gSearchLabel, d$
until ( Count( D ) < CQ( D ) + 1 ) or ( Get Dir$() = StartPath and Count( D ) = CQ( D ) )
until Get Dir$() = StartPath and Count( D ) = CQ( D )
setGadgetVisible gSearchingWindow, cNO
close file 1
restore window gMain
endfunction
`===========================
` CREATE USER INTERFACE
`===========================
function CreateUI()
Global gSearchingWindow
Global gSearchLabel
Global gFound
Global gTotal
gSearchingWindow = createWindow( Cx - 170, Cy - 50, 300, 100, "Scanning Hard Drive for all requested files" , 0, 0, 1, gMain )
gSearchLabel = createLabel( 10, 20, 240, 20, "", gSearchingWindow )
gFound = createLabel( 10, 40, 180, 20, "", gSearchingWindow )
gTotal = createLabel( 200, 40, 90, 20, "", gSearchingWindow )
setGadgetVisible gSearchingWindow, cNO
endfunction