 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Anthoni Gardner Guest
|
Posted: Wed Jul 20, 2005 10:48 pm Post subject: Working out Sub-Paths |
|
|
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
|
Posted: Thu Jul 21, 2005 5:44 am Post subject: Re: Working out Sub-Paths |
|
|
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
|
Posted: Thu Jul 21, 2005 8:05 am Post subject: Re: Working out Sub-Paths |
|
|
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
|
Posted: Thu Jul 21, 2005 11:35 pm Post subject: Re: Working out Sub-Paths |
|
|
listmember wrote:
Thank you so very much.
Wonderful.
Regards
Anthoni
|
|
| Back to top |
|
 |
listmember Guest
|
Posted: Fri Jul 22, 2005 10:35 am Post subject: Re: Working out Sub-Paths |
|
|
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 |
|
 |
|
|
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
|
|