[futurebasic] Re: [FB] Recursive scan folder

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

From: Alain Pastor <apastor@...>
Date: Sun, 27 Jan 2008 23:55:44 +0100
Brian Stevens a crit :
> 
> On Jan 27, 2008, at 3:11 PM, Alain Pastor wrote:
>>>> Thanks Brian & Steve.
>>>>
>>>> ........ but I stopped programming nearly 80 years ago.........
> You really opened the door for comments on this one Alain.
> 
Sorry, just a typo. I meant 800, of course.

> 
>>>>
>>>> The problem is that the file$ function seems to return a wrong 
>>>> FSSpec when it involves a folder (using _FSSpecFolder). The 
>>>> misbehavior arises only when running through FBtoC although the code 
>>>> compiles without errors. On the other hand, it works as expected 
>>>> through FB.
> 
> Do you have an example to recreate the problem?
> 
>>>>
>>>> In the code I posted previously I was not interested in finding a 
>>>> specific folder but rather in dealing with the folder the user has 
>>>> chosen in the Navigation Services dialog box.
> 
> The only previous posts I have from you are the IterateFolder post which 
> doesn't use FILES$ and sending apple events to system processes. I don't 
> see a post like the one mentioned but I've overlooked things before.
> 
> 
> 
>>>>
>> The question still remains: is this a bug in my code or should I 
>> report a bug to the FBtoC team?
> Alain, please post the code snippet showing the problem. If it is a bug 
> that will be the only post necessary.
> 

OK. Here you are:


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

include "Tlbx MoreFilesX.incl"

_kCatalogInfoBitmap = _kFSCatInfoNodeFlags _kFSCatInfoFinderInfo
_kRequestCountPerIteration = ((4096 * 4) / Sizeof(FSCatalogInfo))

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


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 ) )
err = Fn FSpMakeFSRef( spec, fldRef )
Long If ( err == _noErr )
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



Alain