![]() |
DISK I/OFastly find files
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$ '=============== Rick
|