Rocket Division Software

CD/DVD/Blu-Ray/HD-DVD recording, iSCSI and AoE (ATA-over-Ethernet)




 [ 3 posts ] 
AuthorMessage
 Post subject: Walking thru a FileTree
Posted:
Offline

Joined: F
Posts: 8
Hi folks.

I'd like to know how to walk thru a FileTree made from this:

StarBurn_ISO9660JolietFileTree_Create(FTrack, PCHAR(@ErrorText[1]), sizeof(ErrorText), Status,
@SitaBurnerCallback, @FTrackContext, TRUE,
FALSE, // No locked files - do not keep all the handles opened all the time
TRUE, // Use Level2 for ISO9660 names generation
FTrackType);

in which I need to remove some files matching a defined pattern.
I currently use a loop like this one:

procedure ScanDirectory(Track, DirNode: Pointer; FileMask: string);
// procedure recursive ************************
var
NewNode: Pointer;
Attributes: Integer;
FileName: string;
begin
FileName := GetNodeFileName(Track, DirNode);
NewNode := StarBurn_ISO9660JolietFileTree_GetFirstKid(FTrack, DirNode);
while NewNode <> nil do begin
FileName := GetNodeFileName(Track, NewNode);
Attributes := StarBurn_ISO9660JolietFileTree_GetAttributes(FTrack, NewNode);
if (Attributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY then
ScanDirectory(Track, NewNode, FileMask)
else
TestAndDeleteFile(Track, NewNode, FileMask);
NewNode := StarBurn_ISO9660JolietFileTree_GetNextKid(Track, DirNode, NewNode);
end;
end;


But I'm suspicious about the selected line above as it gives the next node but appears to ignore directories.
Something wrong with it ?
Please note that code is DELPHI and this function is recursive and this may be the answer.
My need is to have a working logic so that I can go thru ALL nodes in the tree.

Tanks a lot

Antonio.


Top
 Profile  
 
 Post subject: Re: Walking thru a FileTree
Posted:
Offline

Joined: F
Posts: 8
Hi.

Got the solution on my own.
In the middle of the code, where either a directory or a file is processed, every time a file being selected by the file mask is deleted, the function returns to the caller. The later will restart a scan from the very beginning.
This takes time, of course, but works.

IF you are interested, have a look into the following code:
1. Calling master code snippet:

FIsoRoot := StarBurn_ISO9660JolietFileTree_GetRoot(FTrack);
// the loop is a tentative for eliminatig scan surprises
while (FIsoRoot <> nil) and ScanDirectory(FTrack, FIsoRoot, FileMask) do begin
FIsoRoot := StarBurn_ISO9660JolietFileTree_GetRoot(FTrack);
Res := StarBurn_ISO9660JolietFileTree_SeekToBegin(FTrack, PCHAR(@ErrorText[1]), sizeof(ErrorText), Status);
end;

2. the executive code:

function ScanDirectory(Track, DirNode: Pointer; FileMask: string): Boolean;
// procedure recursive ************************
var
NewNode: Pointer;
Attributes: Integer;
FileName: string;
begin
Result := False;
FileName := GetNodeFileName(Track, DirNode);
NewNode := StarBurn_ISO9660JolietFileTree_GetFirstKid(FTrack, DirNode);
while (NewNode <> nil) and (not Result) do begin
FileName := GetNodeFileName(Track, NewNode);
Attributes := StarBurn_ISO9660JolietFileTree_GetAttributes(FTrack, NewNode);
if (Attributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY then
Result := ScanDirectory(Track, NewNode, FileMask)
else
Result := TestAndDeleteFile(Track, NewNode, FileMask);
// as soon as we delete a node, get out giving control to our caller
if Result then
break;
NewNode := StarBurn_ISO9660JolietFileTree_GetNextKid(Track, DirNode, NewNode);
end;
end;

As a matter of conclusion, whenever a walk is made thru the FileTree and a node is deleted, the walker manager seems to loose control of the walker pointer for subsequent queries for NextKid. I guess this needs some fixing work.

BTW, if the goal is to have a Tree manipulation, some other functionnalities present into the most basic Tree (either visual or not) could be welcome and for instance: HasChildren (instead to have to test for a directory, which is time consuming).

Anyway, this fix is time consuming when the tree has a lot of files (26000 in my case).
On another point of view, I was really looking for something which could help to avoid some files not to be loaded into the tree (aka ZipForge with their ExclustionMasks).

Antonio.


Top
 Profile  
 
 Post subject: Re: Walking thru a FileTree
Posted:
Offline
Site Admin

Joined: F
Posts: 3553
Location: British Virgin Islands
Thank you~ We love self-suppring customers

P.S. I've moved the thread to the right forum.

_________________
Regards,
Anton Kolomyeytsev

Rocket Division Software


Top
 Profile  
 
 [ 3 posts ]