[futurebasic] Recursive scan folder

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2008 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Sat, 26 Jan 2008 12:42:12 +0100
Hi,

I've tried to adapt the old FB example that shows how to scan a folder's 
content recursively for FBtoC compliance. With no great success so far. 
How would you skin that cat?

Here is my attempt (that seems to work OK in FB)


'~'A
'                       Runtime : RNTM Lite.INCL
'~'B

include "Tlbx MoreFilesX.incl"

Clear Local Mode
Local Fn ScanFolderRecursive( @folderRefToScan As .FSRef )
'~'9
Dim   err         As OSStatus
Dim   ignore      As OSStatus
Dim   index       As UInt32
Dim @ iterator    As FSIterator
Dim @ actualCount As Long
Dim   fInfo       As .FileInfo
Xref aryCatInfo(_maxInt) As FSCatalogInfo
Xref aryFSSpec (_maxInt) As FSSpec
Xref aryFSRef  (_maxInt) As FSRef

_kCatalogInfoBitmap = _kFSCatInfoNodeFlags _kFSCatInfoFinderInfo

_kRequestCountPerIteration = ((4096 * 4) / Sizeof(FSCatalogInfo))

err = Fn FSOpenIterator( #folderRefToScan, _kFSIterateFlat, iterator )
If err Then Exit Fn

aryCatInfo = Fn malloc( _kRequestCountPerIteration * Sizeof(FSCatalogInfo) )
aryFSRef   = Fn malloc( _kRequestCountPerIteration * Sizeof(FSRef) )
aryFSSpec  = Fn malloc( _kRequestCountPerIteration * Sizeof(FSSpec) )

Long If aryCatInfo == _nil or aryFSRef == _nil or aryFSSpec == _nil
err = _memFullErr
Xelse
While err == _noErr
err = Fn FSGetCatalogInfoBulk(       iterator, 
                    _kRequestCountPerIteration, 
                                   actualCount, 
                                         #_nil, 
                           _kCatalogInfoBitmap, 
                                   #aryCatInfo, 
                                     #aryFSRef, 
                                    #aryFSSpec, 
                                         #_nil )

Long If ( err == _noErr or err == _errFSNoMoreItems )
Long If actualCount
For index = 0 To actualCount - 1
Print aryFSSpec.name(index);
Long If (aryCatInfo.nodeFlags( index ) 
       And _kFSNodeIsDirectoryMask) == _kFSNodeIsDirectoryMask
Print " (Folder)"
err = Fn ScanFolderRecursive( aryFSRef(index) )
Xelse
fInfo = @aryCatInfo.finderInfo( index )
Print "   (";Mki$(fInfo.fileType);")"
End If
next
End If
End If
Wend

If err == _errFSNoMoreItems Then err = _noErr

End If

If aryCatInfo Then Fn free(aryCatInfo)
If aryFSRef   Then Fn free(aryFSRef)
If aryFSSpec  Then Fn free(aryFSSpec)
ignore = Fn FSCloseIterator( iterator )
End Fn = err


'~Program test

Dim As  OSStatus    err
Dim As  FSSpec      spec
Dim As  FSRef     @ fldRef

Long If Len( Files$( _FSSpecFolder, "Choose a folder",,spec ) )
Long If ( Fn FSpMakeFSRef( spec, fldRef ) == _noErr )
err = Fn FSpMakeFSRef( spec, fldRef )
Print "Iteration start!" : Print
If err == _noErr Then err = Fn ScanFolderRecursive( fldRef )
End If
Print : Print "Final error: ", err
End If

Do
HandleEvents
Until gFBQuit


TIA (will be off for the week-end)

Alain