[futurebasic] Re: [FB] High Speed File Finding

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 1999 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Sat, 09 Oct 1999 12:03:44 -0500

Mel Patrick wrote:

> I'm reasonably sure that this was discussed not too long ago so
> humour my sleight of mind, but whats the fastest way to look through
> a drive(s) to locate a "given" filename (no pathname or fSpec) and
> then return all the matches?
>
> i.e. do a find for a filename called "WheredMelLeaveIt" that was say
> created on a specific date (maybe even match a type and creator).
>
> The date might be handy so I can sort them from newest to oldest. It
> would be nice to get either a pathname or fSpec back that I could
> open.

What you're describing is exactly what the Toolbox function PBCatSearch does.
It's extremely powerful and versatile, which unfortunately implies that it
takes a little work to set it up right.  You could just about write a clone of
"Find File" in FB, using practically nothing but PBCatSearch.  (In fact, I'd
bet 5 bucks that "Find File" is essentially just a front end for PBCatSearch.)

Below is a demo: it finds up to 25 files whose names contain a given input
string.  This is just one of many different ways that PBCatSearch can search.
To get the full scoop on PBCatSearch, check out the following links:

http://developer.apple.com/techpubs/mac/Files/Files-94.html
http://developer.apple.com/techpubs/mac/Files/Files-252.html

'==================================
' PBCatSearch Demo, by Rick Brown
'==================== constants ===================
_maxRequest = 25                                  'Adjust as desired
_searchInfoSize = 104
'===================== globals =====================
DIM RECORD fsRec
  DIM fsVrefNum%
  DIM fsParID&
  DIM 63 fsFilename$
DIM END RECORD _fsRecSize

DIM RECORD catPositionRec
  DIM initialize&
  DIM priv.12
DIM END RECORD _catPositionRec
END GLOBALS
'===================== functions ========================
LOCAL FN PBCatSearchSync(cspBlockAddr&)
  `     MOVE.L  ^cspBlockAddr&,A0
  `     MOVEQ   #$18,D0
  `     DC.W    $A260
  `     MOVE.W  D0,^OSErr
END FN = OSErr
'===================== MAIN ============================
DIM cspBlock.76, searchInfo1.searchInfoSize, searchInfo2.searchInfoSize
DIM fsSpecArray.fsRecSize(_maxRequest)

WINDOW OFF
WINDOW 1
TEXT _monaco, 9
INPUT "File name to search for: "; searchFile$
IF LEN(searchFile$) = 0 THEN END

'(use the following values as an example)
volumeID = -1                                     '(use startup volume)

cspBlock.ioCompletion& = _nil                     '(no completion routine)
cspBlock.ioNamePtr& = _nil                        '(don't use volume name)
cspBlock.ioVRefNum% = volumeID
cspBlock.ioMatchPtr& = @fsSpecArray(0)
cspBlock.ioReqMatchCount& = _maxRequest
cspBlock.ioSearchBits& = _fsSBPartialName%        '(only care about name)
cspBlock.ioSearchInfo1& = @searchInfo1
cspBlock.ioSearchInfo2& = @searchInfo2
cspBlock.ioSearchTime& = 0                        '(no time limit)
cspBlock.ioCatPosition.initialize& = 0            '(start at beginning)
cspBlock.ioOptBuffer& = _nil

'Set values to search for:
searchInfo1.ioNamePtr& = @searchFile$
searchInfo2.ioNamePtr& = _nil

PRINT "Searching..."
OSErr = FN PBCatSearchSync(@cspBlock)
CLS
SELECT CASE OSErr
  CASE _eofErr, _noErr
    count = cspBlock.ioActMatchCount&
    PRINT "Number found:"; count
    LONG IF count > 0
      INPUT "Press RETURN to list them:"; x$
      FOR i = 1 TO count
        PRINT fsSpecArray.fsFilename$(i-1)
      NEXT
    END IF
  CASE ELSE
    PRINT "OSErr = "; OSErr
END SELECT
PRINT
INPUT "Press RETURN to end:" ; x$
'====================================

Hope this helps.
- Rick