BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Working out Sub-Paths

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Thirdparty Tools (General)
View previous topic :: View next topic  
Author Message
Anthoni Gardner
Guest





PostPosted: Wed Jul 20, 2005 10:48 pm    Post subject: Working out Sub-Paths Reply with quote



Hello there,

Given a list of directories such as

C:Documents and SettingsAnthoniMy DocumentsMy Pictures
E:Delphi-AddonsJCLsourcecommon
E:Delphi-AddonsMisc
D:Misc
C:Documents and SettingsAnthoniMy DocumentsMISC

I am trying to work out which ones are the sub-directories of each
other, but I cant seem to get it right in code. I know its a recursive
loop, but all my attempts seem to fail. I seem to be spending too long
on this and wondered if anyone knew of any code or component out there
that can do this for me <grins> A little black box so to speak.

Regards
Anthoni
Back to top
willem van Deursen
Guest





PostPosted: Thu Jul 21, 2005 5:44 am    Post subject: Re: Working out Sub-Paths Reply with quote



the function ExtractFilePath (unit sysutils) might help quite a bit.

Willem

Anthoni Gardner wrote:
Quote:
Hello there,

Given a list of directories such as

C:Documents and SettingsAnthoniMy DocumentsMy Pictures
E:Delphi-AddonsJCLsourcecommon
E:Delphi-AddonsMisc
D:Misc
C:Documents and SettingsAnthoniMy DocumentsMISC

I am trying to work out which ones are the sub-directories of each
other, but I cant seem to get it right in code. I know its a recursive
loop, but all my attempts seem to fail. I seem to be spending too long
on this and wondered if anyone knew of any code or component out there
that can do this for me <grins> A little black box so to speak.

Regards
Anthoni

--
Willem van Deursen, The Netherlands
[email]wvandeursen_nospam (AT) nospam_carthago (DOT) nl[/email]
replace _nospam@nospam_ for @ to get a valid email address
www.carthago.nl


Back to top
listmember
Guest





PostPosted: Thu Jul 21, 2005 8:05 am    Post subject: Re: Working out Sub-Paths Reply with quote



Anthoni Gardner wrote:

Quote:
I am trying to work out which ones are the sub-directories of each
other, but I cant seem to get it right in code. I know its a recursive
loop, but all my attempts seem to fail. I seem to be spending too long
on this and wondered if anyone knew of any code or component out there
that can do this for me <grins> A little black box so to speak.

Here you go.

function IsSubfolder(Path1: String; Path2: String): Boolean;
begin
Result := False;
Path1 := UpperCase(ExcludeTrailingPathDelimiter(Path1));
Path2 := UpperCase(ExcludeTrailingPathDelimiter(Path2));
If (Length(Path1) > 0) and (Length(Path2) > 0) then begin
If Length(Path1) > Length(Path2) then
Result := (Pos(Path2, Path1) = 1)
else Result := (Pos(Path1, Path2) = 1)
end;
end;

Back to top
Anthoni Gardner
Guest





PostPosted: Thu Jul 21, 2005 11:35 pm    Post subject: Re: Working out Sub-Paths Reply with quote

listmember wrote:

Quote:
Here you go.


Thank you so very much.
Wonderful.

Regards
Anthoni

Back to top
listmember
Guest





PostPosted: Fri Jul 22, 2005 10:35 am    Post subject: Re: Working out Sub-Paths Reply with quote

Anthoni Gardner wrote:

Quote:
listmember wrote:

Here you go.


Thank you so very much.
Wonderful.

:-)

No problem.

Actually, a better one would be like this

function IsSubfolder(Path1: String; Path2: String): Boolean;
var
Length1: Integer;
Length2: Integer;
begin
Result := False;
Length1 := Length(Path1);
Length2 := Length(Path2);
If (Length1 > 0) and (Length2 > 0) then begin
Path1 := UpperCase(ExcludeTrailingPathDelimiter(Path1));
Path2 := UpperCase(ExcludeTrailingPathDelimiter(Path2));
If Length1 > Length2 then
Result := (Pos(Path2, Path1) = 1)
else Result := (Pos(Path1, Path2) = 1)
end;
end;

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Thirdparty Tools (General) All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.