#1 Burning Software

It is currently Sat Apr 20, 2024 2:33 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Walking thru a FileTree
PostPosted: Tue Dec 01, 2009 10:13 am 
Offline

Joined: Fri Nov 27, 2009 2:30 pm
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. :mrgreen:
My need is to have a working logic so that I can go thru ALL nodes in the tree. :wink:

Tanks a lot

Antonio.


Top
 Profile  
 
 Post subject: Re: Walking thru a FileTree
PostPosted: Tue Dec 01, 2009 3:00 pm 
Offline

Joined: Fri Nov 27, 2009 2:30 pm
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
PostPosted: Tue Dec 01, 2009 4:24 pm 
Offline
Site Admin

Joined: Fri Jun 18, 2004 12:03 am
Posts: 4089
Location: British Virgin Islands
Thank you~ We love self-suppring customers :)

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group